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;
const long long INF = 1e15 + 15;
void maximize(long long& x, long long y) {
x = max(x, y);
}
int main() {
int n, k;
cin >> n >> k;
vector<int> c(n), s(n);
for (int i = 0; i < n; ++i) {
cin >> c[i];
}
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
vector<vector<vector<long long>>> dp(n, vector<vector<long long>> (3, vector<long long> (k + 1, -INF)));
dp[0][0][0] = 0;
dp[0][1][1] = s[0] - c[0];
if (k == 1) {
dp[0][2][1] = s[0] - c[0];
}
for (int i = 1; i < n; ++i) {
for (int st = 0; st < 3; ++st) {
if (st == 0) {
maximize(dp[i][0][0], dp[i - 1][0][0]);
maximize(dp[i][1][1], dp[i - 1][0][0] + s[i] - c[i]);
} else if (st == 1) {
for (int j = 1; j < k; ++j) {
maximize(dp[i][1][j], dp[i - 1][1][j] - c[i]);
maximize(dp[i][1][j], dp[i - 1][1][j - 1] + s[i] - c[i]);
}
maximize(dp[i][2][k], dp[i - 1][1][k - 1] + s[i] - c[i]);
} else {
maximize(dp[i][2][k], dp[i - 1][2][k]);
}
}
}
cout << dp[n - 1][2][k] << '\n';
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |