Created
April 19, 2020 03:12
-
-
Save niklasjang/a75987fa131c23a0fda701e4bb81eaa7 to your computer and use it in GitHub Desktop.
[PS][그리디]/[BOJ][17451][평행 우주]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int n; | |
int spd[300000]; | |
int main(void) { | |
cin >> n; | |
int i = 0; | |
for (i = 0; i < n; i++) { | |
cin >> spd[i]; | |
} | |
long long ans = 0; | |
for (i = n - 1; i >= 0; i--) { | |
if (ans < spd[i]) ans = 1LL * spd[i]; | |
else if (ans == spd[i]) continue; | |
else { | |
if (ans % spd[i] == 0) continue; | |
ans = 1LL * ((ans / spd[i]) + 1) * spd[i]; | |
} | |
//cout << ans << "\n"; | |
} | |
cout << ans << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment