forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3.cpp
35 lines (29 loc) Β· 964 Bytes
/
3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
using namespace std;
int n; // μ 체 μλ΄ κ°μ
vector<int> t; // κ° μλ΄μ μλ£νλλ° κ±Έλ¦¬λ κΈ°κ°
vector<int> p; // κ° μλ΄μ μλ£νμ λ λ°μ μ μλ κΈμ‘
int dp[16]; // λ€μ΄λλ―Ή νλ‘κ·Έλλ°μ μν 1μ°¨μ DP ν
μ΄λΈ μ΄κΈ°ν
int maxValue;
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
t.push_back(x);
p.push_back(y);
}
// 리μ€νΈλ₯Ό λ€μμλΆν° κ±°κΎΈλ‘ νμΈ
for (int i = n - 1; i >= 0; i--) {
int time = t[i] + i;
// μλ΄μ΄ κΈ°κ° μμ λλλ κ²½μ°
if (time <= n) {
// μ νμμ λ§κ², νμ¬κΉμ§μ μ΅κ³ μ΄μ΅ κ³μ°
dp[i] = max(p[i] + dp[time], maxValue);
maxValue = dp[i];
}
// μλ΄μ΄ κΈ°κ°μ λ²μ΄λλ κ²½μ°
else dp[i] = maxValue;
}
cout << maxValue << '\n';
}