Submission #70469

#TimeUsernameProblemLanguageResultExecution timeMemory
70469Diuven만두 (JOI14_ho_t2)C++14
100 / 100
22 ms1916 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...