# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153901 | arnold518 | 만두 (JOI14_ho_t2) | C++14 | 90 ms | 20240 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>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXM = 1e4;
const int MAXN = 500;
const int INF = 1e8;
int M, N, P[MAXM+10], C[MAXN+10], E[MAXN+10];
int dp[MAXN+10][MAXM+10], ans;
int main()
{
int i, j;
scanf("%d%d", &M, &N);
for(i=1; i<=M; i++) scanf("%d", &P[i]);
sort(P+1, P+M+1, greater<int>());
for(i=1; i<=M; i++) P[i]+=P[i-1];
for(i=1; i<=N; i++) scanf("%d%d", &C[i], &E[i]);
for(i=1; i<=M; i++) dp[0][i]=INF;
for(i=1; i<=N; i++)
{
deque<int> DQ;
for(j=1; j<=M; j++)
{
while(!DQ.empty() && DQ.front()<j-C[i]) DQ.pop_front();
while(!DQ.empty() && dp[i-1][DQ.back()]>=dp[i-1][j-1]) DQ.pop_back();
DQ.push_back(j-1);
dp[i][j]=min(dp[i-1][DQ.front()]+E[i], dp[i-1][j]);
}
}
for(i=1; i<=M; i++) ans=max(ans, P[i]-dp[N][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... |