#include<stdio.h>
#include<algorithm>
using namespace std;
long long dp[2001][2001];
int n;
pair<int, int> p[2000];
int main() {
scanf("%d", &n);
fill(&dp[0][2], &dp[n][n + 1], -1e10);
for (int i = 0; i <n; i++) scanf("%d %d", &p[i].first, &p[i].second);
sort(p, p + n);
for (int i = 1; i<=n; i++){
int a = p[n - i].first, b = p[n - i].second;
for (int j = 0; j <= n; j++){
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j + a - 1 >= 0 && j + a - 1 <= n)
dp[i][j + a - 1] = max(dp[i][j + a - 1], dp[i - 1][j] + b);
}
for (int j = n - 1; j >= 0; j--)
dp[i][j] = max(dp[i][j], dp[i][j + 1]);
}
printf("%lld", dp[n][0]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
32380 KB |
Output is correct |
2 |
Correct |
0 ms |
32380 KB |
Output is correct |
3 |
Correct |
0 ms |
32380 KB |
Output is correct |
4 |
Correct |
0 ms |
32380 KB |
Output is correct |
5 |
Correct |
0 ms |
32380 KB |
Output is correct |
6 |
Correct |
0 ms |
32380 KB |
Output is correct |
7 |
Correct |
0 ms |
32380 KB |
Output is correct |
8 |
Correct |
0 ms |
32380 KB |
Output is correct |
9 |
Correct |
0 ms |
32380 KB |
Output is correct |
10 |
Correct |
0 ms |
32380 KB |
Output is correct |
11 |
Correct |
0 ms |
32380 KB |
Output is correct |
12 |
Correct |
0 ms |
32380 KB |
Output is correct |
13 |
Correct |
0 ms |
32380 KB |
Output is correct |
14 |
Correct |
0 ms |
32380 KB |
Output is correct |
15 |
Correct |
0 ms |
32380 KB |
Output is correct |
16 |
Correct |
0 ms |
32380 KB |
Output is correct |
17 |
Correct |
0 ms |
32380 KB |
Output is correct |
18 |
Correct |
0 ms |
32380 KB |
Output is correct |
19 |
Correct |
0 ms |
32380 KB |
Output is correct |
20 |
Correct |
0 ms |
32380 KB |
Output is correct |
21 |
Correct |
0 ms |
32380 KB |
Output is correct |
22 |
Correct |
0 ms |
32380 KB |
Output is correct |
23 |
Correct |
0 ms |
32380 KB |
Output is correct |
24 |
Correct |
0 ms |
32380 KB |
Output is correct |
25 |
Correct |
0 ms |
32380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
32380 KB |
Output is correct |
2 |
Correct |
0 ms |
32380 KB |
Output is correct |
3 |
Correct |
0 ms |
32380 KB |
Output is correct |
4 |
Correct |
1 ms |
32380 KB |
Output is correct |
5 |
Correct |
1 ms |
32380 KB |
Output is correct |
6 |
Correct |
0 ms |
32380 KB |
Output is correct |
7 |
Correct |
0 ms |
32380 KB |
Output is correct |
8 |
Correct |
6 ms |
32380 KB |
Output is correct |
9 |
Correct |
12 ms |
32380 KB |
Output is correct |
10 |
Correct |
12 ms |
32380 KB |
Output is correct |
11 |
Correct |
6 ms |
32380 KB |
Output is correct |
12 |
Correct |
40 ms |
32380 KB |
Output is correct |
13 |
Correct |
31 ms |
32380 KB |
Output is correct |
14 |
Correct |
31 ms |
32380 KB |
Output is correct |
15 |
Correct |
35 ms |
32380 KB |
Output is correct |
16 |
Correct |
35 ms |
32380 KB |
Output is correct |
17 |
Correct |
30 ms |
32380 KB |
Output is correct |
18 |
Correct |
36 ms |
32380 KB |
Output is correct |
19 |
Correct |
31 ms |
32380 KB |
Output is correct |
20 |
Correct |
31 ms |
32380 KB |
Output is correct |
21 |
Correct |
31 ms |
32380 KB |
Output is correct |
22 |
Correct |
31 ms |
32380 KB |
Output is correct |
23 |
Correct |
35 ms |
32380 KB |
Output is correct |
24 |
Correct |
36 ms |
32380 KB |
Output is correct |
25 |
Correct |
36 ms |
32380 KB |
Output is correct |
26 |
Correct |
36 ms |
32380 KB |
Output is correct |
27 |
Correct |
36 ms |
32380 KB |
Output is correct |
28 |
Correct |
35 ms |
32380 KB |
Output is correct |
29 |
Correct |
34 ms |
32380 KB |
Output is correct |
30 |
Correct |
28 ms |
32380 KB |
Output is correct |
31 |
Correct |
33 ms |
32380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
32380 KB |
Output is correct |
2 |
Correct |
0 ms |
32380 KB |
Output is correct |
3 |
Correct |
0 ms |
32380 KB |
Output is correct |
4 |
Correct |
0 ms |
32380 KB |
Output is correct |
5 |
Correct |
0 ms |
32380 KB |
Output is correct |
6 |
Correct |
0 ms |
32380 KB |
Output is correct |
7 |
Correct |
0 ms |
32380 KB |
Output is correct |
8 |
Correct |
1 ms |
32380 KB |
Output is correct |
9 |
Correct |
8 ms |
32380 KB |
Output is correct |
10 |
Correct |
6 ms |
32380 KB |
Output is correct |
11 |
Correct |
8 ms |
32380 KB |
Output is correct |
12 |
Correct |
4 ms |
32380 KB |
Output is correct |
13 |
Correct |
8 ms |
32380 KB |
Output is correct |
14 |
Correct |
4 ms |
32380 KB |
Output is correct |
15 |
Correct |
12 ms |
32380 KB |
Output is correct |
16 |
Correct |
8 ms |
32380 KB |
Output is correct |
17 |
Correct |
32 ms |
32380 KB |
Output is correct |
18 |
Correct |
36 ms |
32380 KB |
Output is correct |
19 |
Correct |
35 ms |
32380 KB |
Output is correct |
20 |
Correct |
35 ms |
32380 KB |
Output is correct |
21 |
Correct |
32 ms |
32380 KB |
Output is correct |
22 |
Correct |
36 ms |
32380 KB |
Output is correct |
23 |
Correct |
36 ms |
32380 KB |
Output is correct |
24 |
Correct |
32 ms |
32380 KB |
Output is correct |
25 |
Correct |
34 ms |
32380 KB |
Output is correct |
26 |
Correct |
35 ms |
32380 KB |
Output is correct |
27 |
Correct |
35 ms |
32380 KB |
Output is correct |
28 |
Correct |
35 ms |
32380 KB |
Output is correct |
29 |
Correct |
31 ms |
32380 KB |
Output is correct |
30 |
Correct |
35 ms |
32380 KB |
Output is correct |
31 |
Correct |
35 ms |
32380 KB |
Output is correct |
32 |
Correct |
35 ms |
32380 KB |
Output is correct |
33 |
Correct |
31 ms |
32380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
32380 KB |
Output is correct |
2 |
Correct |
36 ms |
32380 KB |
Output is correct |
3 |
Correct |
36 ms |
32380 KB |
Output is correct |
4 |
Correct |
36 ms |
32380 KB |
Output is correct |
5 |
Correct |
35 ms |
32380 KB |
Output is correct |
6 |
Correct |
32 ms |
32380 KB |
Output is correct |
7 |
Correct |
34 ms |
32380 KB |
Output is correct |
8 |
Correct |
32 ms |
32380 KB |
Output is correct |
9 |
Correct |
36 ms |
32380 KB |
Output is correct |
10 |
Correct |
35 ms |
32380 KB |
Output is correct |
11 |
Correct |
39 ms |
32380 KB |
Output is correct |
12 |
Correct |
31 ms |
32380 KB |
Output is correct |
13 |
Correct |
31 ms |
32380 KB |
Output is correct |
14 |
Correct |
36 ms |
32380 KB |
Output is correct |
15 |
Correct |
31 ms |
32380 KB |
Output is correct |
16 |
Correct |
31 ms |
32380 KB |
Output is correct |
17 |
Correct |
31 ms |
32380 KB |
Output is correct |
18 |
Correct |
35 ms |
32380 KB |
Output is correct |
19 |
Correct |
36 ms |
32380 KB |
Output is correct |
20 |
Correct |
29 ms |
32380 KB |
Output is correct |
21 |
Correct |
32 ms |
32380 KB |
Output is correct |
22 |
Correct |
29 ms |
32380 KB |
Output is correct |
23 |
Correct |
33 ms |
32380 KB |
Output is correct |
24 |
Correct |
33 ms |
32380 KB |
Output is correct |
25 |
Correct |
31 ms |
32380 KB |
Output is correct |