답안 #46824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46824 2018-04-23T16:45:53 Z ffresh 스트랩 (JOI14_straps) C++17
100 / 100
8 ms 1344 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 2005;

ll dp[N];
ll pre[N];

int main(){
    //freopen("input.txt","r",stdin);

    int n;
    scanf("%d",&n);

    int a,b;
    vector<pair<int,int> > bag;

    ll cur = 1,cost = 0;
    ll pos= 1;

    for(int i=1;i<=n+1;++i)dp[i]= -1e18;

    for(int i=0;i<n;++i){
        scanf("%d%d",&a,&b);
        if(b<0){
            if(a<=1)continue;
            bag.push_back(make_pair(a,b));
        }   
        else{
            if(a==0){
                pre[pos++]= b;
            }
            else{
                cur += a-1;
                cost +=b;
            }
        }
    }

    sort(pre+1,pre+pos,greater<ll>());

    for(int i=1;i<=n;++i)
        pre[i]= pre[i-1] + pre[i];
    cur= min(cur,(ll)n);
    dp[cur]= cost;
    for(int i=0;i<bag.size();++i){
        a = bag[i].first, b= bag[i].second;
        for(int j=n;j>=cur;--j){
            int nb = min(n ,j +a-1);
            dp[nb]= max(dp[nb],dp[j]+b);
        }
    }
    ll ret= 0;
    for(int i=cur;i<=n;++i){
        int sz= i;
        ret = max(ret, dp[i] + pre[sz]);
    }
    cout<<ret<<endl;

    return 0;
}

Compilation message

straps.cpp: In function 'int main()':
straps.cpp:49:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<bag.size();++i){
                 ~^~~~~~~~~~~
straps.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
straps.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 472 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 1 ms 680 KB Output is correct
14 Correct 2 ms 680 KB Output is correct
15 Correct 2 ms 680 KB Output is correct
16 Correct 2 ms 680 KB Output is correct
17 Correct 2 ms 680 KB Output is correct
18 Correct 2 ms 680 KB Output is correct
19 Correct 2 ms 680 KB Output is correct
20 Correct 2 ms 680 KB Output is correct
21 Correct 2 ms 680 KB Output is correct
22 Correct 2 ms 680 KB Output is correct
23 Correct 2 ms 680 KB Output is correct
24 Correct 2 ms 680 KB Output is correct
25 Correct 2 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 680 KB Output is correct
2 Correct 2 ms 680 KB Output is correct
3 Correct 2 ms 680 KB Output is correct
4 Correct 2 ms 680 KB Output is correct
5 Correct 2 ms 680 KB Output is correct
6 Correct 2 ms 680 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 2 ms 680 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 3 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 680 KB Output is correct
15 Correct 2 ms 780 KB Output is correct
16 Correct 2 ms 780 KB Output is correct
17 Correct 2 ms 780 KB Output is correct
18 Correct 2 ms 780 KB Output is correct
19 Correct 2 ms 780 KB Output is correct
20 Correct 3 ms 780 KB Output is correct
21 Correct 3 ms 780 KB Output is correct
22 Correct 2 ms 780 KB Output is correct
23 Correct 3 ms 780 KB Output is correct
24 Correct 3 ms 780 KB Output is correct
25 Correct 2 ms 908 KB Output is correct
26 Correct 3 ms 908 KB Output is correct
27 Correct 2 ms 908 KB Output is correct
28 Correct 2 ms 908 KB Output is correct
29 Correct 3 ms 908 KB Output is correct
30 Correct 2 ms 924 KB Output is correct
31 Correct 2 ms 944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 944 KB Output is correct
2 Correct 2 ms 944 KB Output is correct
3 Correct 2 ms 944 KB Output is correct
4 Correct 2 ms 944 KB Output is correct
5 Correct 2 ms 944 KB Output is correct
6 Correct 2 ms 944 KB Output is correct
7 Correct 2 ms 944 KB Output is correct
8 Correct 2 ms 944 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 960 KB Output is correct
11 Correct 2 ms 960 KB Output is correct
12 Correct 3 ms 960 KB Output is correct
13 Correct 2 ms 1080 KB Output is correct
14 Correct 2 ms 1080 KB Output is correct
15 Correct 2 ms 1080 KB Output is correct
16 Correct 2 ms 1080 KB Output is correct
17 Correct 3 ms 1080 KB Output is correct
18 Correct 3 ms 1080 KB Output is correct
19 Correct 3 ms 1080 KB Output is correct
20 Correct 4 ms 1080 KB Output is correct
21 Correct 3 ms 1080 KB Output is correct
22 Correct 3 ms 1080 KB Output is correct
23 Correct 2 ms 1080 KB Output is correct
24 Correct 3 ms 1080 KB Output is correct
25 Correct 4 ms 1080 KB Output is correct
26 Correct 3 ms 1080 KB Output is correct
27 Correct 3 ms 1080 KB Output is correct
28 Correct 2 ms 1080 KB Output is correct
29 Correct 3 ms 1080 KB Output is correct
30 Correct 2 ms 1080 KB Output is correct
31 Correct 2 ms 1080 KB Output is correct
32 Correct 2 ms 1080 KB Output is correct
33 Correct 8 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1080 KB Output is correct
2 Correct 2 ms 1080 KB Output is correct
3 Correct 2 ms 1080 KB Output is correct
4 Correct 2 ms 1080 KB Output is correct
5 Correct 2 ms 1080 KB Output is correct
6 Correct 2 ms 1080 KB Output is correct
7 Correct 2 ms 1080 KB Output is correct
8 Correct 2 ms 1080 KB Output is correct
9 Correct 3 ms 1088 KB Output is correct
10 Correct 3 ms 1088 KB Output is correct
11 Correct 3 ms 1088 KB Output is correct
12 Correct 3 ms 1088 KB Output is correct
13 Correct 3 ms 1088 KB Output is correct
14 Correct 3 ms 1088 KB Output is correct
15 Correct 3 ms 1088 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 3 ms 1120 KB Output is correct
18 Correct 2 ms 1172 KB Output is correct
19 Correct 2 ms 1280 KB Output is correct
20 Correct 3 ms 1280 KB Output is correct
21 Correct 3 ms 1280 KB Output is correct
22 Correct 3 ms 1280 KB Output is correct
23 Correct 3 ms 1344 KB Output is correct
24 Correct 3 ms 1344 KB Output is correct
25 Correct 2 ms 1344 KB Output is correct