Skip to content

Commit 2eb4d16

Browse files
committed
[Week02] BOJ: 퇴사2
1 parent a06f54f commit 2eb4d16

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
4+
using namespace std;
5+
6+
int n, ret;
7+
int arr[1500001][2];
8+
int dp[1500001];
9+
10+
int main() {
11+
ios_base::sync_with_stdio(false);
12+
cin.tie(NULL);
13+
cout.tie(NULL);
14+
15+
cin >> n;
16+
17+
for (int i = 0; i < n; i++) {
18+
cin >> arr[i][0] >> arr[i][1];
19+
}
20+
21+
for (int i = n - 1; i >= 0; i--) {
22+
if (i + arr[i][0] <= n) {
23+
dp[i] = max(dp[i + 1], arr[i][1] + dp[i + arr[i][0]]);
24+
} else {
25+
dp[i] = dp[i + 1];
26+
}
27+
}
28+
29+
cout << dp[0] << '\n';
30+
return 0;
31+
}

0 commit comments

Comments
 (0)