Submission #1071878

#TimeUsernameProblemLanguageResultExecution timeMemory
1071878NeroZeinTricks of the Trade (CEOI23_trade)C++17
25 / 100
1060 ms2097152 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...