Submission #6011

#TimeUsernameProblemLanguageResultExecution timeMemory
6011imsifile스트랩 (JOI14_straps)C++98
100 / 100
0 ms1128 KiB
#include<stdio.h> #include<algorithm> using namespace std; int n, sok=1, ba1[2010], sum[2010], ba2[2010][2], dy[2010], acn, bcn, pre, dap; int mx(int p, int q){ if(!p)return q; else if(!q)return p; return p>q?p:q; } int main(){ int i, j, k; scanf("%d", &n); for(i=0; i<n; i++){ scanf("%d%d", &j, &k); if(j && k>=0)sok+=j-1, pre+=k; else if(j>1)ba2[bcn][0]=j-1, ba2[bcn++][1]=k; else if(k>0)ba1[acn++]=k; } sort(ba1, ba1+acn); if(sok>acn)sok=acn; for(i=1; i<=acn; i++)sum[i]=sum[i-1]+ba1[acn-i]; for(i=0; i<bcn; i++){ for(j=acn-sok; j>0; j--){ if(j<=ba2[i][0])dy[j]=mx(dy[j], ba2[i][1]); else if(dy[j-ba2[i][0]])dy[j]=mx(dy[j], dy[j-ba2[i][0]]+ba2[i][1]); } } for(i=0; i<=acn-sok; i++){ if(!dy[i] && i)continue; if(dap<pre+sum[sok+i]+dy[i])dap=pre+sum[sok+i]+dy[i]; } printf("%d", dap); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...