Submission #1097314

#TimeUsernameProblemLanguageResultExecution timeMemory
1097314vjudge1Feast (NOI19_feast)C++17
18 / 100
475 ms47316 KiB
#include<bits/stdc++.h> using namespace std; const int N = 3e5 + 2; int n, vis[N][2]; long long pan, a[N]; pair<long long, int> mem[N][2]; pair<long long, int> operator + (pair<long long, int> x, pair<long long, int> y) { return make_pair(x.first + y.first, x.second + y.second); } // 1-> (i - 1) not taken vice verca pair<long long, int> dp(int i, int f) { if (i == n) return {0, 0}; if (vis[i][f]) return mem[i][f]; vis[i][f] = 1; auto &ret = mem[i][f]; ret = dp(i + 1, 1); ret = max(ret, dp(i + 1, 0) + make_pair(-pan * f + a[i], f)); return ret; } pair<long long, int> get(long long x) { pan = x; memset(vis, 0, sizeof(vis)); return dp(0, 1); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; // auto z = get(1); // cout << z.first << endl; // cout << z.second << endl; long long l = 0, r = 1LL << 42, res = 0; while (l <= r) { long long m = (l + r) / 2; auto [x, y] = get(m); if (y < k) { r = m - 1; } else l = m + 1, res = x + k * m;; } cout << res << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...