Submission #863745

#TimeUsernameProblemLanguageResultExecution timeMemory
863745TAhmed33A Difficult(y) Choice (BOI21_books)C++17
100 / 100
1 ms608 KiB
#include <bits/stdc++.h> #include <books.h> #pragma GCC optimize ("trapv") using namespace std; typedef long long ll; bool check (ll sum, ll a) { return sum >= a && sum <= 2 * a; } void solve (int n, int k, ll a, int s) { map <int, ll> dd; int l = k, r = n; for (int i = 1; i < k; i++) dd[i] = skim(i); int ans = -1; while (l <= r) { int mid = (l + r) >> 1; if (!dd.count(mid)) dd[mid] = skim(mid); if (dd[mid] > a) { r = mid - 1; ans = mid; } else { l = mid + 1; } } ll sum = 0; for (int i = 1; i < k; i++) sum += dd[i]; if (ans != -1) { sum += dd[ans]; if (check(sum, a)) { vector <int> t; for (int i = 1; i < k; i++) t.push_back(i); t.push_back(ans); answer(t); } } if (ans == -1) ans = n + 1; if (!dd.count(k)) dd[k] = skim(k); vector <pair <int, ll>> u; for (int i = 1; i <= k; i++) { if (!dd.count(i)) dd[i] = skim(i); u.push_back({i, dd[i]}); } for (int i = max(1, ans - k); i < ans; i++) { if (!dd.count(i)) dd[i] = skim(i); u.push_back({i, dd[i]}); } sum = 0; for (int i = 0; i < k; i++) sum += u[i].second; if (check(sum, a)) { vector <int> t; for (int i = 0; i < k; i++) t.push_back(u[i].first); sort(t.begin(), t.end()); answer(t); } for (int i = k; i < (int)u.size(); i++) { sum -= u[i - k].second; sum += u[i].second; if (check(sum, a)) { vector <int> t; for (int j = i - k + 1; j <= i; j++) { t.push_back(u[j].first); } sort(t.begin(), t.end()); answer(t); } } 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...