Submission #25555

# Submission time Handle Problem Language Result Execution time Memory
25555 2017-06-23T04:44:56 Z 시제연(#1075) 스트랩 (JOI14_straps) C++
100 / 100
49 ms 85708 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll knap[2100][5100], INF = 1LL<<50;
int n, bia = 2010;
int a[2100], b[2100];

int main() {
    int i, j, k;

    //freopen("input","r",stdin);

    scanf("%d",&n);
    for (i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
    for (i=1;i<=n;i++) a[i]--;
    for (j=0;j<5100;j++) knap[0][j] = -INF;
    knap[0][bia] = 0;
    ll res = 0;
    for (i=1;i<=n;i++) {
        for (j=0;j<=n+bia+1;j++) {
            knap[i][j] = knap[i-1][j];
            if (j==n+bia+1) {
                knap[i][j] = max(knap[i][j],knap[i-1][j]+b[i]);
                for (k=j-a[i];k<=n+bia;k++) knap[i][j] = max(knap[i][j],knap[i-1][k]+b[i]);
            }
            else if (j-a[i]>=0&&j-a[i]<=n+bia) knap[i][j] = max(knap[i][j],knap[i-1][j-a[i]]+b[i]);
            if (i==n&&j-bia>=-1) res = max(res,knap[i][j]);
        }
    }
    printf("%lld\n",res);

    return 0;
}

Compilation message

straps.cpp: In function 'int main()':
straps.cpp:16:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
straps.cpp:17:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
                                                 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 85708 KB Output is correct
2 Correct 0 ms 85708 KB Output is correct
3 Correct 0 ms 85708 KB Output is correct
4 Correct 0 ms 85708 KB Output is correct
5 Correct 0 ms 85708 KB Output is correct
6 Correct 0 ms 85708 KB Output is correct
7 Correct 0 ms 85708 KB Output is correct
8 Correct 0 ms 85708 KB Output is correct
9 Correct 0 ms 85708 KB Output is correct
10 Correct 0 ms 85708 KB Output is correct
11 Correct 0 ms 85708 KB Output is correct
12 Correct 0 ms 85708 KB Output is correct
13 Correct 0 ms 85708 KB Output is correct
14 Correct 0 ms 85708 KB Output is correct
15 Correct 0 ms 85708 KB Output is correct
16 Correct 0 ms 85708 KB Output is correct
17 Correct 0 ms 85708 KB Output is correct
18 Correct 0 ms 85708 KB Output is correct
19 Correct 0 ms 85708 KB Output is correct
20 Correct 0 ms 85708 KB Output is correct
21 Correct 0 ms 85708 KB Output is correct
22 Correct 0 ms 85708 KB Output is correct
23 Correct 0 ms 85708 KB Output is correct
24 Correct 0 ms 85708 KB Output is correct
25 Correct 0 ms 85708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 85708 KB Output is correct
2 Correct 0 ms 85708 KB Output is correct
3 Correct 0 ms 85708 KB Output is correct
4 Correct 0 ms 85708 KB Output is correct
5 Correct 0 ms 85708 KB Output is correct
6 Correct 0 ms 85708 KB Output is correct
7 Correct 0 ms 85708 KB Output is correct
8 Correct 9 ms 85708 KB Output is correct
9 Correct 9 ms 85708 KB Output is correct
10 Correct 16 ms 85708 KB Output is correct
11 Correct 6 ms 85708 KB Output is correct
12 Correct 16 ms 85708 KB Output is correct
13 Correct 23 ms 85708 KB Output is correct
14 Correct 19 ms 85708 KB Output is correct
15 Correct 33 ms 85708 KB Output is correct
16 Correct 16 ms 85708 KB Output is correct
17 Correct 13 ms 85708 KB Output is correct
18 Correct 16 ms 85708 KB Output is correct
19 Correct 26 ms 85708 KB Output is correct
20 Correct 13 ms 85708 KB Output is correct
21 Correct 29 ms 85708 KB Output is correct
22 Correct 23 ms 85708 KB Output is correct
23 Correct 26 ms 85708 KB Output is correct
24 Correct 33 ms 85708 KB Output is correct
25 Correct 23 ms 85708 KB Output is correct
26 Correct 29 ms 85708 KB Output is correct
27 Correct 36 ms 85708 KB Output is correct
28 Correct 39 ms 85708 KB Output is correct
29 Correct 23 ms 85708 KB Output is correct
30 Correct 33 ms 85708 KB Output is correct
31 Correct 39 ms 85708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 85708 KB Output is correct
2 Correct 0 ms 85708 KB Output is correct
3 Correct 0 ms 85708 KB Output is correct
4 Correct 0 ms 85708 KB Output is correct
5 Correct 0 ms 85708 KB Output is correct
6 Correct 0 ms 85708 KB Output is correct
7 Correct 0 ms 85708 KB Output is correct
8 Correct 0 ms 85708 KB Output is correct
9 Correct 9 ms 85708 KB Output is correct
10 Correct 9 ms 85708 KB Output is correct
11 Correct 6 ms 85708 KB Output is correct
12 Correct 13 ms 85708 KB Output is correct
13 Correct 6 ms 85708 KB Output is correct
14 Correct 9 ms 85708 KB Output is correct
15 Correct 13 ms 85708 KB Output is correct
16 Correct 6 ms 85708 KB Output is correct
17 Correct 19 ms 85708 KB Output is correct
18 Correct 36 ms 85708 KB Output is correct
19 Correct 26 ms 85708 KB Output is correct
20 Correct 23 ms 85708 KB Output is correct
21 Correct 29 ms 85708 KB Output is correct
22 Correct 29 ms 85708 KB Output is correct
23 Correct 26 ms 85708 KB Output is correct
24 Correct 29 ms 85708 KB Output is correct
25 Correct 39 ms 85708 KB Output is correct
26 Correct 36 ms 85708 KB Output is correct
27 Correct 16 ms 85708 KB Output is correct
28 Correct 26 ms 85708 KB Output is correct
29 Correct 16 ms 85708 KB Output is correct
30 Correct 39 ms 85708 KB Output is correct
31 Correct 33 ms 85708 KB Output is correct
32 Correct 33 ms 85708 KB Output is correct
33 Correct 19 ms 85708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 85708 KB Output is correct
2 Correct 9 ms 85708 KB Output is correct
3 Correct 29 ms 85708 KB Output is correct
4 Correct 43 ms 85708 KB Output is correct
5 Correct 19 ms 85708 KB Output is correct
6 Correct 29 ms 85708 KB Output is correct
7 Correct 26 ms 85708 KB Output is correct
8 Correct 16 ms 85708 KB Output is correct
9 Correct 49 ms 85708 KB Output is correct
10 Correct 39 ms 85708 KB Output is correct
11 Correct 29 ms 85708 KB Output is correct
12 Correct 23 ms 85708 KB Output is correct
13 Correct 23 ms 85708 KB Output is correct
14 Correct 19 ms 85708 KB Output is correct
15 Correct 9 ms 85708 KB Output is correct
16 Correct 43 ms 85708 KB Output is correct
17 Correct 23 ms 85708 KB Output is correct
18 Correct 39 ms 85708 KB Output is correct
19 Correct 13 ms 85708 KB Output is correct
20 Correct 26 ms 85708 KB Output is correct
21 Correct 23 ms 85708 KB Output is correct
22 Correct 23 ms 85708 KB Output is correct
23 Correct 26 ms 85708 KB Output is correct
24 Correct 33 ms 85708 KB Output is correct
25 Correct 13 ms 85708 KB Output is correct