# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153904 | mhy908 | 만두 (JOI14_ho_t2) | C++14 | 42 ms | 20140 KiB |
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>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define llinf 8987654321987654321
#define inf 1987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int n, m;
int p[10010], sum[10010];
int c[510], e[510];
int dp[510][10010];
int fin[10010];
int ans;
int main()
{
scanf("%d %d", &n, &m);
for(int i=1; i<=n; i++)scanf("%d", &p[i]);
sort(p+1, p+n+1, greater<int>());
for(int i=1; i<=n; i++)sum[i]=p[i]+sum[i-1];
for(int i=1; i<=m; i++)scanf("%d %d", &c[i], &e[i]);
for(int i=1; i<=10000; i++)dp[0][i]=inf;
for(int i=1; i<=m; i++){
for(int j=0; j<c[i]; j++)dp[i][j]=dp[i-1][j];
for(int j=0; j+c[i]<=10000; j++)dp[i][j+c[i]]=min(dp[i-1][j+c[i]], dp[i-1][j]+e[i]);
for(int j=9999; j>=0; j--)dp[i][j]=min(dp[i][j], dp[i][j+1]);
}
for(int i=1; i<=n; i++)ans=max(ans, sum[i]-dp[m][i]);
printf("%d", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |