# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
261938 | patrikpavic2 | Cake 3 (JOI19_cake3) | C++17 | 152 ms | 73828 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 <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef pair < int, int > pii;
typedef long long ll;
const int N = 2e3 + 50;
const ll INF = 1e18;
ll dp[N][N];
int C[N], V[N], n, m;
vector < pii > v;
ll f(int i, int j){
if(i == 0) return (j != 0) * (-INF);
if(dp[i][j] != -1) return dp[i][j];
if(j == 1)
return dp[i][j] = max(f(i - 1, 1), 2LL * C[i] + V[i]);
return dp[i][j] = max(f(i - 1, j), f(i - 1, j - 1) + V[i]);
}
int main(){
memset(dp, -1, sizeof(dp));
scanf("%d%d", &n, &m);
for(int i = 0;i < n;i++){
int x, y; scanf("%d%d", &x, &y);
v.PB({y, x});
}
sort(v.begin(), v.end());
for(int i = 0;i < n;i++)
C[i + 1] = v[i].X, V[i + 1] = v[i].Y;
ll sol = -INF;
for(int i = m;i <= n;i++)
sol = max(sol, f(i, m) - 2LL * C[i]);
printf("%lld\n", sol);
}
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... |