#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (1100000099)
#define INFLL (1100000000000000099ll)
#define MOD (1000000007)
#define MAXN (2005)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
int d[MAXN][MAXN];
bool chk[MAXN][MAXN];
int A[MAXN], B[MAXN], P[MAXN];
int N, Ans;
int main() {
for(int i = 0; i < MAXN; i++) fill(d[i], d[i]+MAXN, -INF);
scanf("%d", &N);
for(int i = 1; i <= N; i++) scanf("%d%d", &A[i], &B[i]);
for(int i = 1; i <= N; i++) A[i]--;
for(int i = 1; i <= N; i++) P[i] = i;
sort(P+1, P+N+1, [&](const int& a, const int& b) -> bool { return A[a] > A[b]; });
d[0][1] = 0; chk[0][1] = true;
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= N; j++) {
if(!chk[i-1][j]) continue;
upmax(d[i][min(N, j+A[P[i]])], d[i-1][j] + B[P[i]]);
chk[i][min(N, j+A[P[i]])] = true;
}
for(int j = 0; j <= N; j++) {
if(!chk[i-1][j]) continue;
chk[i][j] = true; upmax(d[i][j], d[i-1][j]);
}
}
for(int i = 0; i <= N; i++) upmax(Ans, d[N][i]);
printf("%d\n", Ans);
return 0;
}
Compilation message
straps.cpp: In function 'int main()':
straps.cpp:46:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
straps.cpp:47:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= N; i++) scanf("%d%d", &A[i], &B[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
21672 KB |
Output is correct |
2 |
Correct |
3 ms |
21672 KB |
Output is correct |
3 |
Correct |
6 ms |
21672 KB |
Output is correct |
4 |
Correct |
6 ms |
21672 KB |
Output is correct |
5 |
Correct |
0 ms |
21672 KB |
Output is correct |
6 |
Correct |
0 ms |
21672 KB |
Output is correct |
7 |
Correct |
6 ms |
21672 KB |
Output is correct |
8 |
Correct |
0 ms |
21672 KB |
Output is correct |
9 |
Correct |
3 ms |
21672 KB |
Output is correct |
10 |
Correct |
3 ms |
21672 KB |
Output is correct |
11 |
Correct |
9 ms |
21672 KB |
Output is correct |
12 |
Correct |
6 ms |
21672 KB |
Output is correct |
13 |
Correct |
6 ms |
21672 KB |
Output is correct |
14 |
Correct |
0 ms |
21672 KB |
Output is correct |
15 |
Correct |
6 ms |
21672 KB |
Output is correct |
16 |
Correct |
9 ms |
21672 KB |
Output is correct |
17 |
Correct |
6 ms |
21672 KB |
Output is correct |
18 |
Correct |
0 ms |
21672 KB |
Output is correct |
19 |
Correct |
0 ms |
21672 KB |
Output is correct |
20 |
Correct |
3 ms |
21672 KB |
Output is correct |
21 |
Correct |
0 ms |
21672 KB |
Output is correct |
22 |
Correct |
9 ms |
21672 KB |
Output is correct |
23 |
Correct |
6 ms |
21672 KB |
Output is correct |
24 |
Correct |
3 ms |
21672 KB |
Output is correct |
25 |
Correct |
3 ms |
21672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
21672 KB |
Output is correct |
2 |
Correct |
3 ms |
21672 KB |
Output is correct |
3 |
Correct |
0 ms |
21672 KB |
Output is correct |
4 |
Correct |
0 ms |
21672 KB |
Output is correct |
5 |
Correct |
0 ms |
21672 KB |
Output is correct |
6 |
Correct |
0 ms |
21672 KB |
Output is correct |
7 |
Correct |
0 ms |
21672 KB |
Output is correct |
8 |
Correct |
6 ms |
21672 KB |
Output is correct |
9 |
Correct |
3 ms |
21672 KB |
Output is correct |
10 |
Correct |
6 ms |
21672 KB |
Output is correct |
11 |
Correct |
9 ms |
21672 KB |
Output is correct |
12 |
Correct |
16 ms |
21672 KB |
Output is correct |
13 |
Correct |
13 ms |
21672 KB |
Output is correct |
14 |
Correct |
16 ms |
21672 KB |
Output is correct |
15 |
Correct |
13 ms |
21672 KB |
Output is correct |
16 |
Correct |
9 ms |
21672 KB |
Output is correct |
17 |
Correct |
6 ms |
21672 KB |
Output is correct |
18 |
Correct |
13 ms |
21672 KB |
Output is correct |
19 |
Correct |
13 ms |
21672 KB |
Output is correct |
20 |
Correct |
16 ms |
21672 KB |
Output is correct |
21 |
Correct |
26 ms |
21672 KB |
Output is correct |
22 |
Correct |
19 ms |
21672 KB |
Output is correct |
23 |
Correct |
13 ms |
21672 KB |
Output is correct |
24 |
Correct |
13 ms |
21672 KB |
Output is correct |
25 |
Correct |
23 ms |
21672 KB |
Output is correct |
26 |
Correct |
23 ms |
21672 KB |
Output is correct |
27 |
Correct |
23 ms |
21672 KB |
Output is correct |
28 |
Correct |
9 ms |
21672 KB |
Output is correct |
29 |
Correct |
23 ms |
21672 KB |
Output is correct |
30 |
Correct |
13 ms |
21672 KB |
Output is correct |
31 |
Correct |
19 ms |
21672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
21672 KB |
Output is correct |
2 |
Correct |
0 ms |
21672 KB |
Output is correct |
3 |
Correct |
3 ms |
21672 KB |
Output is correct |
4 |
Correct |
0 ms |
21672 KB |
Output is correct |
5 |
Correct |
0 ms |
21672 KB |
Output is correct |
6 |
Correct |
9 ms |
21672 KB |
Output is correct |
7 |
Correct |
3 ms |
21672 KB |
Output is correct |
8 |
Correct |
0 ms |
21672 KB |
Output is correct |
9 |
Correct |
6 ms |
21672 KB |
Output is correct |
10 |
Correct |
9 ms |
21672 KB |
Output is correct |
11 |
Correct |
6 ms |
21672 KB |
Output is correct |
12 |
Correct |
9 ms |
21672 KB |
Output is correct |
13 |
Correct |
6 ms |
21672 KB |
Output is correct |
14 |
Correct |
3 ms |
21672 KB |
Output is correct |
15 |
Correct |
6 ms |
21672 KB |
Output is correct |
16 |
Correct |
6 ms |
21672 KB |
Output is correct |
17 |
Correct |
9 ms |
21672 KB |
Output is correct |
18 |
Correct |
16 ms |
21672 KB |
Output is correct |
19 |
Correct |
16 ms |
21672 KB |
Output is correct |
20 |
Correct |
13 ms |
21672 KB |
Output is correct |
21 |
Correct |
13 ms |
21672 KB |
Output is correct |
22 |
Correct |
9 ms |
21672 KB |
Output is correct |
23 |
Correct |
9 ms |
21672 KB |
Output is correct |
24 |
Correct |
13 ms |
21672 KB |
Output is correct |
25 |
Correct |
9 ms |
21672 KB |
Output is correct |
26 |
Correct |
9 ms |
21672 KB |
Output is correct |
27 |
Correct |
9 ms |
21672 KB |
Output is correct |
28 |
Correct |
6 ms |
21672 KB |
Output is correct |
29 |
Correct |
16 ms |
21672 KB |
Output is correct |
30 |
Correct |
6 ms |
21672 KB |
Output is correct |
31 |
Correct |
3 ms |
21672 KB |
Output is correct |
32 |
Correct |
9 ms |
21672 KB |
Output is correct |
33 |
Correct |
16 ms |
21672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
21672 KB |
Output is correct |
2 |
Correct |
13 ms |
21672 KB |
Output is correct |
3 |
Correct |
19 ms |
21672 KB |
Output is correct |
4 |
Correct |
23 ms |
21672 KB |
Output is correct |
5 |
Correct |
23 ms |
21672 KB |
Output is correct |
6 |
Correct |
23 ms |
21672 KB |
Output is correct |
7 |
Correct |
29 ms |
21672 KB |
Output is correct |
8 |
Correct |
26 ms |
21672 KB |
Output is correct |
9 |
Correct |
23 ms |
21672 KB |
Output is correct |
10 |
Correct |
23 ms |
21672 KB |
Output is correct |
11 |
Correct |
39 ms |
21672 KB |
Output is correct |
12 |
Correct |
19 ms |
21672 KB |
Output is correct |
13 |
Correct |
29 ms |
21672 KB |
Output is correct |
14 |
Correct |
29 ms |
21672 KB |
Output is correct |
15 |
Correct |
23 ms |
21672 KB |
Output is correct |
16 |
Correct |
23 ms |
21672 KB |
Output is correct |
17 |
Correct |
39 ms |
21672 KB |
Output is correct |
18 |
Correct |
33 ms |
21672 KB |
Output is correct |
19 |
Correct |
19 ms |
21672 KB |
Output is correct |
20 |
Correct |
23 ms |
21672 KB |
Output is correct |
21 |
Correct |
19 ms |
21672 KB |
Output is correct |
22 |
Correct |
16 ms |
21672 KB |
Output is correct |
23 |
Correct |
19 ms |
21672 KB |
Output is correct |
24 |
Correct |
16 ms |
21672 KB |
Output is correct |
25 |
Correct |
13 ms |
21672 KB |
Output is correct |