#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359
int N;
vector<pair<int,int> > items;
int dp[2000][2000];
int solve(int now, int p){
if(now == N) return 0;
if(p > N-now) return solve(now,N-now);
if(p == 0) return 0;
if(dp[now][p] != -1) return dp[now][p];
return dp[now][p] = max(solve(now+1,p),solve(now+1,p-1+items[now].first)+items[now].second);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(9);
cin >> N;
for(int i=0;i <N; i++){
int A,B;
cin >> A >> B;
items.push_back(MP(A,B));
for(int j=0; j<N; j++) dp[i][j] = -1;
}
sort(items.begin(), items.end());
reverse(items.begin(), items.end());
cout << solve(0,1) << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
432 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
740 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
12 ms |
8192 KB |
Output is correct |
9 |
Correct |
13 ms |
8320 KB |
Output is correct |
10 |
Correct |
13 ms |
8192 KB |
Output is correct |
11 |
Correct |
11 ms |
8192 KB |
Output is correct |
12 |
Correct |
28 ms |
16128 KB |
Output is correct |
13 |
Correct |
27 ms |
16128 KB |
Output is correct |
14 |
Correct |
24 ms |
16128 KB |
Output is correct |
15 |
Correct |
31 ms |
16128 KB |
Output is correct |
16 |
Correct |
24 ms |
16128 KB |
Output is correct |
17 |
Correct |
26 ms |
16120 KB |
Output is correct |
18 |
Correct |
34 ms |
16128 KB |
Output is correct |
19 |
Correct |
38 ms |
16128 KB |
Output is correct |
20 |
Correct |
45 ms |
16128 KB |
Output is correct |
21 |
Correct |
58 ms |
16204 KB |
Output is correct |
22 |
Correct |
39 ms |
16124 KB |
Output is correct |
23 |
Correct |
43 ms |
16120 KB |
Output is correct |
24 |
Correct |
43 ms |
16128 KB |
Output is correct |
25 |
Correct |
37 ms |
16128 KB |
Output is correct |
26 |
Correct |
50 ms |
16176 KB |
Output is correct |
27 |
Correct |
45 ms |
16180 KB |
Output is correct |
28 |
Correct |
17 ms |
16112 KB |
Output is correct |
29 |
Correct |
26 ms |
16256 KB |
Output is correct |
30 |
Correct |
22 ms |
16228 KB |
Output is correct |
31 |
Correct |
18 ms |
16156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
896 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
14 ms |
8320 KB |
Output is correct |
10 |
Correct |
11 ms |
8320 KB |
Output is correct |
11 |
Correct |
12 ms |
8320 KB |
Output is correct |
12 |
Correct |
11 ms |
8192 KB |
Output is correct |
13 |
Correct |
13 ms |
8192 KB |
Output is correct |
14 |
Correct |
11 ms |
8192 KB |
Output is correct |
15 |
Correct |
13 ms |
8320 KB |
Output is correct |
16 |
Correct |
11 ms |
8320 KB |
Output is correct |
17 |
Correct |
24 ms |
16128 KB |
Output is correct |
18 |
Correct |
25 ms |
16128 KB |
Output is correct |
19 |
Correct |
25 ms |
16128 KB |
Output is correct |
20 |
Correct |
25 ms |
16128 KB |
Output is correct |
21 |
Correct |
27 ms |
16128 KB |
Output is correct |
22 |
Correct |
25 ms |
16128 KB |
Output is correct |
23 |
Correct |
26 ms |
16128 KB |
Output is correct |
24 |
Correct |
26 ms |
16128 KB |
Output is correct |
25 |
Correct |
27 ms |
16128 KB |
Output is correct |
26 |
Correct |
32 ms |
16124 KB |
Output is correct |
27 |
Correct |
26 ms |
16100 KB |
Output is correct |
28 |
Correct |
33 ms |
16128 KB |
Output is correct |
29 |
Correct |
33 ms |
16128 KB |
Output is correct |
30 |
Correct |
25 ms |
16128 KB |
Output is correct |
31 |
Correct |
27 ms |
16128 KB |
Output is correct |
32 |
Correct |
27 ms |
16120 KB |
Output is correct |
33 |
Correct |
25 ms |
16176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
16176 KB |
Output is correct |
2 |
Correct |
41 ms |
16128 KB |
Output is correct |
3 |
Correct |
36 ms |
16128 KB |
Output is correct |
4 |
Correct |
32 ms |
16128 KB |
Output is correct |
5 |
Correct |
45 ms |
16128 KB |
Output is correct |
6 |
Correct |
43 ms |
16128 KB |
Output is correct |
7 |
Correct |
54 ms |
16256 KB |
Output is correct |
8 |
Correct |
51 ms |
16180 KB |
Output is correct |
9 |
Correct |
48 ms |
16128 KB |
Output is correct |
10 |
Correct |
41 ms |
16128 KB |
Output is correct |
11 |
Correct |
42 ms |
16128 KB |
Output is correct |
12 |
Correct |
54 ms |
16128 KB |
Output is correct |
13 |
Correct |
33 ms |
16128 KB |
Output is correct |
14 |
Correct |
46 ms |
16128 KB |
Output is correct |
15 |
Correct |
41 ms |
16128 KB |
Output is correct |
16 |
Correct |
45 ms |
16128 KB |
Output is correct |
17 |
Correct |
39 ms |
16128 KB |
Output is correct |
18 |
Correct |
44 ms |
16200 KB |
Output is correct |
19 |
Correct |
22 ms |
16128 KB |
Output is correct |
20 |
Correct |
18 ms |
16128 KB |
Output is correct |
21 |
Correct |
17 ms |
16248 KB |
Output is correct |
22 |
Correct |
17 ms |
16128 KB |
Output is correct |
23 |
Correct |
20 ms |
16128 KB |
Output is correct |
24 |
Correct |
20 ms |
16128 KB |
Output is correct |
25 |
Correct |
18 ms |
16120 KB |
Output is correct |