Submission #46824

#TimeUsernameProblemLanguageResultExecution timeMemory
46824ffresh스트랩 (JOI14_straps)C++17
100 / 100
8 ms1344 KiB
#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 (stderr)

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);
         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...