Submission #810686

#TimeUsernameProblemLanguageResultExecution timeMemory
810686MyCodeA Difficult(y) Choice (BOI21_books)C++17
0 / 100
2 ms684 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; void solve(int n, int k, long long A, int S) { int a[n + 1]; for (int i = 1; i <= n; i++) a[i] = skim(i); if (k == 1) { exit(-1); return; } int pref[n + 1]; pref[0] = 0; for (int i = 1; i <= n; i++) pref[i] = a[i] + pref[i - 1]; function<int(int, int)> sum = [&](int l, int r) { return pref[r] - pref[l - 1]; }; for (int i = 1; i <= n; i++) { if (sum(i, i + k - 1) >= A && sum(i, i + k - 1) <= 2 * A) { vector<int> ans; for (int j = i; j < i + k; j++) ans.emplace_back(j); answer(ans); return; } }; int s[n + 1]; for (int i = 1; i + k - 2 <= n; i++) s[i] = sum(i, i + k - 2); for (int i = k; i <= n; i++) { int l = 1, r = i - k + 1; while (r - l > 1) { int m = (l + r) >> 1; if (s[m] + a[i] >= A) r = m; else l = m; } int ind = -1; if (s[l] + a[i] >= A)ind = l; else if (s[r] + a[i] >= A)ind = r; if (ind != -1 && s[ind] + a[i] <= 2 * A) { vector<int> ans; for (int j = ind; j < ind + k - 1; j++) ans.emplace_back(j); ans.emplace_back(i); answer(ans); return; } } impossible(); }
#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...