Submission #46819

#TimeUsernameProblemLanguageResultExecution timeMemory
46819ffresh스트랩 (JOI14_straps)C++17
45 / 100
8 ms1984 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 2005; int dp[N]; int pre[N]; int main(){ //freopen("input.txt","r",stdin); int n; scanf("%d",&n); int a,b; vector<pair<int,int> > bag; int cur = 1,cost = 0; int pos= 1; for(int i=1;i<=n+1;++i)dp[i]= -2e9-150; dp[1]= 0; 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<int>()); for(int i=1;i<=n;++i) pre[i]= pre[i-1] + pre[i]; 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); } } int 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:28: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...