#include <cstdio>
#include <algorithm>
struct strap{int c,h;}a[2005];
int cmp(strap p, strap q){return p.c>q.c;}
int n;
int dp[2005][2005];
int f(int avail, int pos){
if(pos==n) return 0;
if(avail>n) avail=n;
if(avail<0) return 0;
if(dp[avail][pos]) return dp[avail][pos];
return dp[avail][pos]=std::max(f(avail+a[pos+1].c-1,pos+1),f(avail,pos+1)-a[pos+1].h)+a[pos].h;
}
int main(){
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d %d",&a[i].c,&a[i].h);
}
std::sort(a,a+n,cmp);
printf("%d",std::max(f(a[0].c,0),f(1,0)-a[0].h));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
16804 KB |
Output is correct |
2 |
Correct |
0 ms |
16804 KB |
Output is correct |
3 |
Correct |
0 ms |
16804 KB |
Output is correct |
4 |
Correct |
0 ms |
16804 KB |
Output is correct |
5 |
Correct |
0 ms |
16804 KB |
Output is correct |
6 |
Correct |
0 ms |
16804 KB |
Output is correct |
7 |
Correct |
0 ms |
16804 KB |
Output is correct |
8 |
Correct |
0 ms |
16804 KB |
Output is correct |
9 |
Correct |
0 ms |
16804 KB |
Output is correct |
10 |
Correct |
0 ms |
16804 KB |
Output is correct |
11 |
Correct |
0 ms |
16804 KB |
Output is correct |
12 |
Correct |
0 ms |
16804 KB |
Output is correct |
13 |
Correct |
0 ms |
16804 KB |
Output is correct |
14 |
Correct |
0 ms |
16804 KB |
Output is correct |
15 |
Correct |
0 ms |
16804 KB |
Output is correct |
16 |
Correct |
0 ms |
16804 KB |
Output is correct |
17 |
Correct |
0 ms |
16804 KB |
Output is correct |
18 |
Correct |
0 ms |
16804 KB |
Output is correct |
19 |
Correct |
0 ms |
16804 KB |
Output is correct |
20 |
Correct |
0 ms |
16804 KB |
Output is correct |
21 |
Correct |
0 ms |
16804 KB |
Output is correct |
22 |
Correct |
0 ms |
16804 KB |
Output is correct |
23 |
Correct |
0 ms |
16804 KB |
Output is correct |
24 |
Correct |
0 ms |
16804 KB |
Output is correct |
25 |
Correct |
0 ms |
16804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
16804 KB |
Output is correct |
2 |
Correct |
0 ms |
16804 KB |
Output is correct |
3 |
Correct |
0 ms |
16804 KB |
Output is correct |
4 |
Correct |
0 ms |
16804 KB |
Output is correct |
5 |
Correct |
0 ms |
16804 KB |
Output is correct |
6 |
Correct |
0 ms |
16804 KB |
Output is correct |
7 |
Correct |
0 ms |
16804 KB |
Output is correct |
8 |
Correct |
4 ms |
16804 KB |
Output is correct |
9 |
Correct |
4 ms |
16804 KB |
Output is correct |
10 |
Correct |
4 ms |
16804 KB |
Output is correct |
11 |
Correct |
0 ms |
16804 KB |
Output is correct |
12 |
Correct |
16 ms |
16804 KB |
Output is correct |
13 |
Correct |
16 ms |
16804 KB |
Output is correct |
14 |
Correct |
12 ms |
16804 KB |
Output is correct |
15 |
Correct |
12 ms |
16804 KB |
Output is correct |
16 |
Correct |
4 ms |
16804 KB |
Output is correct |
17 |
Correct |
16 ms |
16804 KB |
Output is correct |
18 |
Correct |
16 ms |
16804 KB |
Output is correct |
19 |
Correct |
36 ms |
16804 KB |
Output is correct |
20 |
Correct |
60 ms |
16804 KB |
Output is correct |
21 |
Correct |
76 ms |
16804 KB |
Output is correct |
22 |
Correct |
8 ms |
16804 KB |
Output is correct |
23 |
Correct |
60 ms |
16804 KB |
Output is correct |
24 |
Correct |
20 ms |
16804 KB |
Output is correct |
25 |
Correct |
52 ms |
16804 KB |
Output is correct |
26 |
Correct |
48 ms |
16804 KB |
Output is correct |
27 |
Correct |
60 ms |
16804 KB |
Output is correct |
28 |
Correct |
68 ms |
16804 KB |
Output is correct |
29 |
Correct |
40 ms |
16804 KB |
Output is correct |
30 |
Correct |
40 ms |
16804 KB |
Output is correct |
31 |
Correct |
36 ms |
16804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
16804 KB |
Output is correct |
2 |
Correct |
0 ms |
16804 KB |
Output is correct |
3 |
Correct |
0 ms |
16804 KB |
Output is correct |
4 |
Correct |
0 ms |
16804 KB |
Output is correct |
5 |
Correct |
0 ms |
16804 KB |
Output is correct |
6 |
Correct |
0 ms |
16804 KB |
Output is correct |
7 |
Correct |
0 ms |
16804 KB |
Output is correct |
8 |
Correct |
0 ms |
16804 KB |
Output is correct |
9 |
Correct |
0 ms |
16804 KB |
Output is correct |
10 |
Correct |
0 ms |
16804 KB |
Output is correct |
11 |
Correct |
0 ms |
16804 KB |
Output is correct |
12 |
Correct |
0 ms |
16804 KB |
Output is correct |
13 |
Correct |
4 ms |
16804 KB |
Output is correct |
14 |
Correct |
0 ms |
16804 KB |
Output is correct |
15 |
Correct |
4 ms |
16804 KB |
Output is correct |
16 |
Correct |
0 ms |
16804 KB |
Output is correct |
17 |
Correct |
12 ms |
16804 KB |
Output is correct |
18 |
Correct |
8 ms |
16804 KB |
Output is correct |
19 |
Correct |
4 ms |
16804 KB |
Output is correct |
20 |
Correct |
12 ms |
16804 KB |
Output is correct |
21 |
Correct |
20 ms |
16804 KB |
Output is correct |
22 |
Correct |
12 ms |
16804 KB |
Output is correct |
23 |
Correct |
12 ms |
16804 KB |
Output is correct |
24 |
Correct |
16 ms |
16804 KB |
Output is correct |
25 |
Correct |
16 ms |
16804 KB |
Output is correct |
26 |
Correct |
12 ms |
16804 KB |
Output is correct |
27 |
Correct |
12 ms |
16804 KB |
Output is correct |
28 |
Correct |
12 ms |
16804 KB |
Output is correct |
29 |
Correct |
16 ms |
16804 KB |
Output is correct |
30 |
Correct |
8 ms |
16804 KB |
Output is correct |
31 |
Correct |
8 ms |
16804 KB |
Output is correct |
32 |
Correct |
16 ms |
16804 KB |
Output is correct |
33 |
Correct |
0 ms |
16804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
16804 KB |
Output is correct |
2 |
Correct |
36 ms |
16804 KB |
Output is correct |
3 |
Correct |
24 ms |
16804 KB |
Output is correct |
4 |
Correct |
24 ms |
16804 KB |
Output is correct |
5 |
Correct |
48 ms |
16804 KB |
Output is correct |
6 |
Correct |
48 ms |
16804 KB |
Output is correct |
7 |
Correct |
40 ms |
16804 KB |
Output is correct |
8 |
Correct |
56 ms |
16804 KB |
Output is correct |
9 |
Correct |
52 ms |
16804 KB |
Output is correct |
10 |
Correct |
52 ms |
16804 KB |
Output is correct |
11 |
Correct |
92 ms |
16804 KB |
Output is correct |
12 |
Correct |
80 ms |
16804 KB |
Output is correct |
13 |
Correct |
80 ms |
16804 KB |
Output is correct |
14 |
Correct |
76 ms |
16804 KB |
Output is correct |
15 |
Correct |
60 ms |
16804 KB |
Output is correct |
16 |
Correct |
76 ms |
16804 KB |
Output is correct |
17 |
Correct |
60 ms |
16804 KB |
Output is correct |
18 |
Correct |
40 ms |
16804 KB |
Output is correct |
19 |
Correct |
40 ms |
16804 KB |
Output is correct |
20 |
Correct |
40 ms |
16804 KB |
Output is correct |
21 |
Correct |
32 ms |
16804 KB |
Output is correct |
22 |
Correct |
44 ms |
16804 KB |
Output is correct |
23 |
Correct |
40 ms |
16804 KB |
Output is correct |
24 |
Correct |
40 ms |
16804 KB |
Output is correct |
25 |
Correct |
56 ms |
16804 KB |
Output is correct |