#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
const int N = 2002;
const int inf = 2e9 + 7;
typedef pair<int,int> ii;
int f[N][N];
ii rope[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 1 ; i <= n ; ++i) {
cin >> rope[i].X;
cin >> rope[i].Y;
}
sort(rope + 1, rope + 1 + n,greater<ii>());
for(int i = n ; i >= 1 ; --i)
for(int j = 0 ; j <= n ; ++j) {
if (i > n) {
f[i][j] = 0;
continue;
}
f[i][j] = max(f[i + 1][j],j > 0 ? f[i + 1][min(j - 1 + rope[i].X,n)] + rope[i].Y : 0);
}
cout << f[1][1] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
13 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
764 KB |
Output is correct |
7 |
Correct |
2 ms |
760 KB |
Output is correct |
8 |
Correct |
10 ms |
8184 KB |
Output is correct |
9 |
Correct |
10 ms |
8184 KB |
Output is correct |
10 |
Correct |
11 ms |
8184 KB |
Output is correct |
11 |
Correct |
10 ms |
8184 KB |
Output is correct |
12 |
Correct |
24 ms |
16020 KB |
Output is correct |
13 |
Correct |
23 ms |
15992 KB |
Output is correct |
14 |
Correct |
23 ms |
15992 KB |
Output is correct |
15 |
Correct |
23 ms |
15996 KB |
Output is correct |
16 |
Correct |
23 ms |
15980 KB |
Output is correct |
17 |
Correct |
23 ms |
15992 KB |
Output is correct |
18 |
Correct |
23 ms |
15992 KB |
Output is correct |
19 |
Correct |
23 ms |
15996 KB |
Output is correct |
20 |
Correct |
23 ms |
16060 KB |
Output is correct |
21 |
Correct |
24 ms |
15992 KB |
Output is correct |
22 |
Correct |
23 ms |
15992 KB |
Output is correct |
23 |
Correct |
23 ms |
15992 KB |
Output is correct |
24 |
Correct |
24 ms |
15992 KB |
Output is correct |
25 |
Correct |
23 ms |
15992 KB |
Output is correct |
26 |
Correct |
23 ms |
16120 KB |
Output is correct |
27 |
Correct |
24 ms |
16024 KB |
Output is correct |
28 |
Correct |
23 ms |
15992 KB |
Output is correct |
29 |
Correct |
23 ms |
15992 KB |
Output is correct |
30 |
Correct |
23 ms |
15992 KB |
Output is correct |
31 |
Correct |
23 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
2 ms |
804 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
10 ms |
8188 KB |
Output is correct |
10 |
Correct |
11 ms |
8184 KB |
Output is correct |
11 |
Correct |
10 ms |
8184 KB |
Output is correct |
12 |
Correct |
10 ms |
8184 KB |
Output is correct |
13 |
Correct |
10 ms |
8184 KB |
Output is correct |
14 |
Correct |
11 ms |
8156 KB |
Output is correct |
15 |
Correct |
10 ms |
8184 KB |
Output is correct |
16 |
Correct |
10 ms |
8184 KB |
Output is correct |
17 |
Correct |
23 ms |
15992 KB |
Output is correct |
18 |
Correct |
23 ms |
15992 KB |
Output is correct |
19 |
Correct |
24 ms |
15992 KB |
Output is correct |
20 |
Correct |
26 ms |
15992 KB |
Output is correct |
21 |
Correct |
23 ms |
15992 KB |
Output is correct |
22 |
Correct |
23 ms |
15992 KB |
Output is correct |
23 |
Correct |
26 ms |
15992 KB |
Output is correct |
24 |
Correct |
23 ms |
15992 KB |
Output is correct |
25 |
Correct |
23 ms |
16064 KB |
Output is correct |
26 |
Correct |
24 ms |
16032 KB |
Output is correct |
27 |
Correct |
24 ms |
15992 KB |
Output is correct |
28 |
Correct |
23 ms |
15992 KB |
Output is correct |
29 |
Correct |
23 ms |
15996 KB |
Output is correct |
30 |
Correct |
25 ms |
16060 KB |
Output is correct |
31 |
Correct |
23 ms |
15992 KB |
Output is correct |
32 |
Correct |
23 ms |
15992 KB |
Output is correct |
33 |
Correct |
23 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
15992 KB |
Output is correct |
2 |
Correct |
24 ms |
16100 KB |
Output is correct |
3 |
Correct |
23 ms |
15992 KB |
Output is correct |
4 |
Correct |
23 ms |
15992 KB |
Output is correct |
5 |
Correct |
24 ms |
15964 KB |
Output is correct |
6 |
Correct |
23 ms |
15992 KB |
Output is correct |
7 |
Correct |
23 ms |
15992 KB |
Output is correct |
8 |
Correct |
23 ms |
15992 KB |
Output is correct |
9 |
Correct |
23 ms |
15992 KB |
Output is correct |
10 |
Correct |
26 ms |
15992 KB |
Output is correct |
11 |
Correct |
26 ms |
15992 KB |
Output is correct |
12 |
Correct |
24 ms |
15992 KB |
Output is correct |
13 |
Correct |
24 ms |
15996 KB |
Output is correct |
14 |
Correct |
27 ms |
15992 KB |
Output is correct |
15 |
Correct |
25 ms |
15992 KB |
Output is correct |
16 |
Correct |
23 ms |
15964 KB |
Output is correct |
17 |
Correct |
24 ms |
15992 KB |
Output is correct |
18 |
Correct |
24 ms |
15992 KB |
Output is correct |
19 |
Correct |
26 ms |
15992 KB |
Output is correct |
20 |
Correct |
23 ms |
15996 KB |
Output is correct |
21 |
Correct |
23 ms |
15992 KB |
Output is correct |
22 |
Correct |
24 ms |
15992 KB |
Output is correct |
23 |
Correct |
23 ms |
15992 KB |
Output is correct |
24 |
Correct |
23 ms |
15992 KB |
Output is correct |
25 |
Correct |
23 ms |
15992 KB |
Output is correct |