File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change 1
- // Authored by : Hot6Mania
1
+ // Authored by : sukam09
2
2
// Co-authored by : -
3
- // http://boj.kr/e27e5b8dfc314c618c8975a2452026aa
3
+ // http://boj.kr/f954e10df8224f1189c74c9a8566396d
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
- int n;
8
- int t[20 ], p[20 ], d[20 ];
7
+ int t[20 ];
8
+ int p[20 ];
9
+ int d[20 ]; // i번째 일에 상담을 시작했을 때 얻을 수 있는 최대 수익
9
10
10
11
int main (void ){
11
12
ios::sync_with_stdio (0 );
12
13
cin.tie (0 );
13
14
15
+ int n;
14
16
cin >> n;
15
- for (int i = 0 ; i < n; ++i) cin >> t[i] >> p[i];
16
17
17
- for (int i = 0 ; i < n; ++i){
18
- d[i] = max (d[i], d[i-1 ]);
19
- if (i + t[i] <= n + 1 )
20
- d[i + t[i]] = max (d[i + t[i]], d[i] + p[i]);
21
- }
18
+ for (int i = 1 ; i <= n; i++) cin >> t[i] >> p[i];
22
19
20
+ for (int i = n; i >= 1 ; i--) {
21
+ // i번째 일에 상담을 할 수 있을 경우
22
+ if (i + t[i] <= n + 1 ) {
23
+ // i번째 일에 상담을 했을 때와 상담을 하지 않았을 때 얻을 수 있는 수익 중 최대 수익을 취함
24
+ d[i] = max (d[i + t[i]] + p[i], d[i + 1 ]);
25
+ }
26
+ else d[i] = d[i + 1 ];
27
+ }
28
+
23
29
cout << *max_element (d, d + n + 1 );
24
30
}
You can’t perform that action at this time.
0 commit comments