Submission #687518

#TimeUsernameProblemLanguageResultExecution timeMemory
687518speedyArdaK blocks (IZhO14_blocks)C++14
0 / 100
1 ms212 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; const int MAXN = 1e5+5; ll pref[MAXN], suf[MAXN], in[MAXN]; int main() { int n, k; cin >> n >> k; vector<int> max_idx; pref[0] = suf[n+1] = 0; for(int i = 1; i <= n; i++) { cin >> in[i]; pref[i] = pref[i - 1] + in[i]; if(max_idx.size() == 0 || in[max_idx[0]] <= in[i]) { if(!max_idx.empty() && in[max_idx[0]] < in[i]) max_idx.clear(); max_idx.push_back(i); } } /*for(int i = n; i >= 1; i--) { suf[i] = suf[i + 1] + in[i]; }*/ ll ans = 1e18; for(int idx : max_idx) { //cout << idx << "\n"; ll temp = 1e18; int right = n; ll other = 0; while(right > max(idx, n - k + 1)) { other += in[right]; right--; } right++; for(int left = 0; left <= min(k - 1, idx - 1); left++) { while(max(0, (n - right)) + left + 1 < k && left <= min(k - 1, idx - 1)) left++; if(max(0, n - right) + left + 1 < k) break; temp = min(temp, pref[left] + in[idx] + other); if(right == n+1) break; other -= in[right]; right++; } ans = min(temp, ans); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...