Submission #13625

#TimeUsernameProblemLanguageResultExecution timeMemory
13625dohyun0324만두 팔기 (JOI14_manju)C++98
100 / 100
23 ms1204 KiB
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int sum,dap,n,m,a[10010],c[510],e[510],d[2][10010]; int main() { int i,j; scanf("%d %d",&m,&n); for(i=1;i<=m;i++) scanf("%d",&a[i]); sort(a+1,a+m+1); reverse(a+1,a+m+1); for(i=1;i<=n;i++) { scanf("%d %d",&c[i],&e[i]); } for(i=0;i<=m;i++) d[0][i]=2147483647; d[0][0]=0; for(i=1;i<=n;i++) { for(j=0;j<=m;j++) d[i%2][j]=d[(i+1)%2][j]; for(j=0;j<=m;j++) { if(d[(i+1)%2][j]!=2147483647) d[i%2][min(m,j+c[i])]=min(d[i%2][min(m,j+c[i])],d[(i+1)%2][j]+e[i]); } } for(i=1;i<=m;i++) { sum+=a[i]; if(dap<sum-d[n%2][i]) dap=sum-d[n%2][i]; } printf("%d",dap); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...