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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=500010, inf=2e9;
int n, m;
int P[10010];
int S[10010];
int E[510];
int C[510];
int D[10010];
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>m>>n;
for(int i=1; i<=m; i++) cin>>P[i];
for(int i=1; i<=n; i++) cin>>C[i]>>E[i];
sort(P+1, P+m+1, greater<int>());
for(int i=1; i<=m; i++) S[i]=S[i-1]+P[i];
for(int i=1; i<=m; i++) D[i]=inf;
D[0]=0;
for(int i=1; i<=n; i++){
for(int j=m; j>=0; j--)
D[min(j+C[i], m)]=min(D[min(j+C[i], m)], D[j]+E[i]);
}
int ans=0;
for(int i=1; i<=m; i++) ans=max(ans, S[i]-D[i]);
cout<<ans;
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... |