#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
typedef pair<int, int> ii;
const int N = 2e3 + 5;
const int inf = 1e14;
int n, dp[N][N];
ii a[N];
signed main() {
cin.tie(0), ios_base::sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i].fi >> a[i].se;
sort(a + 1, a + 1 + n);
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++)
dp[i][j] = -inf;
}
dp[0][0] = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j <= n; j++) {
if(dp[i][j] == -inf) continue;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
if(a[i + 1].fi == 0)
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + a[i + 1].se);
if(a[i + 1].fi)
dp[i + 1][max(j - a[i + 1].fi + 1, 1ll)] = max(dp[i + 1][max(j - a[i + 1].fi + 1, 1ll)], dp[i][j] + a[i + 1].se);
}
}
cout << max(dp[n][1], 0ll);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
31736 KB |
Output is correct |
2 |
Correct |
29 ms |
31736 KB |
Output is correct |
3 |
Correct |
27 ms |
31736 KB |
Output is correct |
4 |
Correct |
28 ms |
31724 KB |
Output is correct |
5 |
Correct |
28 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31864 KB |
Output is correct |
7 |
Correct |
28 ms |
31736 KB |
Output is correct |
8 |
Correct |
28 ms |
31736 KB |
Output is correct |
9 |
Correct |
22 ms |
31736 KB |
Output is correct |
10 |
Correct |
28 ms |
31836 KB |
Output is correct |
11 |
Correct |
28 ms |
31832 KB |
Output is correct |
12 |
Correct |
27 ms |
31736 KB |
Output is correct |
13 |
Correct |
28 ms |
31736 KB |
Output is correct |
14 |
Correct |
28 ms |
31864 KB |
Output is correct |
15 |
Correct |
29 ms |
31788 KB |
Output is correct |
16 |
Correct |
28 ms |
31740 KB |
Output is correct |
17 |
Correct |
28 ms |
31864 KB |
Output is correct |
18 |
Correct |
28 ms |
31748 KB |
Output is correct |
19 |
Correct |
33 ms |
31864 KB |
Output is correct |
20 |
Correct |
71 ms |
31808 KB |
Output is correct |
21 |
Correct |
28 ms |
31864 KB |
Output is correct |
22 |
Correct |
28 ms |
31792 KB |
Output is correct |
23 |
Correct |
28 ms |
31736 KB |
Output is correct |
24 |
Correct |
28 ms |
31864 KB |
Output is correct |
25 |
Correct |
28 ms |
31784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
31864 KB |
Output is correct |
2 |
Correct |
28 ms |
31864 KB |
Output is correct |
3 |
Correct |
28 ms |
31864 KB |
Output is correct |
4 |
Correct |
31 ms |
31864 KB |
Output is correct |
5 |
Correct |
33 ms |
31736 KB |
Output is correct |
6 |
Correct |
28 ms |
31864 KB |
Output is correct |
7 |
Correct |
28 ms |
31736 KB |
Output is correct |
8 |
Correct |
31 ms |
31864 KB |
Output is correct |
9 |
Correct |
31 ms |
31864 KB |
Output is correct |
10 |
Correct |
40 ms |
31864 KB |
Output is correct |
11 |
Correct |
30 ms |
31864 KB |
Output is correct |
12 |
Correct |
38 ms |
31864 KB |
Output is correct |
13 |
Correct |
38 ms |
31864 KB |
Output is correct |
14 |
Correct |
38 ms |
31864 KB |
Output is correct |
15 |
Correct |
37 ms |
31864 KB |
Output is correct |
16 |
Correct |
37 ms |
31864 KB |
Output is correct |
17 |
Correct |
37 ms |
31844 KB |
Output is correct |
18 |
Correct |
37 ms |
31868 KB |
Output is correct |
19 |
Correct |
37 ms |
31880 KB |
Output is correct |
20 |
Correct |
36 ms |
31864 KB |
Output is correct |
21 |
Correct |
37 ms |
31864 KB |
Output is correct |
22 |
Correct |
36 ms |
31864 KB |
Output is correct |
23 |
Correct |
36 ms |
31864 KB |
Output is correct |
24 |
Correct |
36 ms |
31868 KB |
Output is correct |
25 |
Correct |
36 ms |
31864 KB |
Output is correct |
26 |
Correct |
36 ms |
31864 KB |
Output is correct |
27 |
Correct |
37 ms |
31864 KB |
Output is correct |
28 |
Correct |
36 ms |
31864 KB |
Output is correct |
29 |
Correct |
33 ms |
31864 KB |
Output is correct |
30 |
Correct |
33 ms |
31864 KB |
Output is correct |
31 |
Correct |
33 ms |
31912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
31864 KB |
Output is correct |
2 |
Correct |
28 ms |
31840 KB |
Output is correct |
3 |
Correct |
27 ms |
31864 KB |
Output is correct |
4 |
Correct |
28 ms |
31736 KB |
Output is correct |
5 |
Correct |
28 ms |
31864 KB |
Output is correct |
6 |
Correct |
28 ms |
31864 KB |
Output is correct |
7 |
Correct |
28 ms |
31736 KB |
Output is correct |
8 |
Correct |
28 ms |
31860 KB |
Output is correct |
9 |
Correct |
31 ms |
31776 KB |
Output is correct |
10 |
Correct |
31 ms |
31800 KB |
Output is correct |
11 |
Correct |
30 ms |
31868 KB |
Output is correct |
12 |
Correct |
31 ms |
31992 KB |
Output is correct |
13 |
Correct |
31 ms |
31864 KB |
Output is correct |
14 |
Correct |
30 ms |
31864 KB |
Output is correct |
15 |
Correct |
36 ms |
31864 KB |
Output is correct |
16 |
Correct |
30 ms |
31864 KB |
Output is correct |
17 |
Correct |
39 ms |
31836 KB |
Output is correct |
18 |
Correct |
39 ms |
31864 KB |
Output is correct |
19 |
Correct |
38 ms |
31864 KB |
Output is correct |
20 |
Correct |
44 ms |
31864 KB |
Output is correct |
21 |
Correct |
38 ms |
31864 KB |
Output is correct |
22 |
Correct |
38 ms |
31864 KB |
Output is correct |
23 |
Correct |
37 ms |
31864 KB |
Output is correct |
24 |
Correct |
37 ms |
31864 KB |
Output is correct |
25 |
Correct |
37 ms |
31864 KB |
Output is correct |
26 |
Correct |
43 ms |
31864 KB |
Output is correct |
27 |
Correct |
41 ms |
31864 KB |
Output is correct |
28 |
Correct |
37 ms |
31820 KB |
Output is correct |
29 |
Correct |
36 ms |
31864 KB |
Output is correct |
30 |
Correct |
36 ms |
31864 KB |
Output is correct |
31 |
Correct |
37 ms |
31864 KB |
Output is correct |
32 |
Correct |
37 ms |
31864 KB |
Output is correct |
33 |
Correct |
33 ms |
31864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
31864 KB |
Output is correct |
2 |
Correct |
37 ms |
31872 KB |
Output is correct |
3 |
Correct |
36 ms |
31864 KB |
Output is correct |
4 |
Correct |
37 ms |
31992 KB |
Output is correct |
5 |
Correct |
36 ms |
31864 KB |
Output is correct |
6 |
Correct |
36 ms |
31864 KB |
Output is correct |
7 |
Correct |
36 ms |
31864 KB |
Output is correct |
8 |
Correct |
36 ms |
31892 KB |
Output is correct |
9 |
Correct |
36 ms |
31864 KB |
Output is correct |
10 |
Correct |
36 ms |
31868 KB |
Output is correct |
11 |
Correct |
37 ms |
31864 KB |
Output is correct |
12 |
Correct |
36 ms |
31864 KB |
Output is correct |
13 |
Correct |
36 ms |
31864 KB |
Output is correct |
14 |
Correct |
36 ms |
31864 KB |
Output is correct |
15 |
Correct |
43 ms |
31864 KB |
Output is correct |
16 |
Correct |
40 ms |
31864 KB |
Output is correct |
17 |
Correct |
36 ms |
31864 KB |
Output is correct |
18 |
Correct |
36 ms |
31864 KB |
Output is correct |
19 |
Correct |
39 ms |
31864 KB |
Output is correct |
20 |
Correct |
33 ms |
31860 KB |
Output is correct |
21 |
Correct |
33 ms |
31864 KB |
Output is correct |
22 |
Correct |
33 ms |
31864 KB |
Output is correct |
23 |
Correct |
33 ms |
31864 KB |
Output is correct |
24 |
Correct |
33 ms |
31864 KB |
Output is correct |
25 |
Correct |
36 ms |
31808 KB |
Output is correct |