This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |