Submission #540447

#TimeUsernameProblemLanguageResultExecution timeMemory
540447elazarkorenA Difficult(y) Choice (BOI21_books)C++17
100 / 100
3 ms388 KiB
#include <bits/stdc++.h> #include "books.h" #define x first #define y second #define all(v) v.begin(), v.end() #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vii; typedef vector<bool> vb; const int MAX_N = 2e5; ll books[MAX_N]; ll ask(int i) { if (books[i]) return books[i]; return books[i] = skim(i); } vi Solve(int n, int k, long long a) { ll sum = 0; vi l, r; for (int i = 1; i <= k; i++) { sum += ask(i); l.push_back(i); } if (sum > 2 * a) { impossible(); return {}; } if (a <= sum) { return l; } for (int i = k; i; i--) { sum -= books[i]; l.pop_back(); ll x = ask(n - k + i); if (x + sum < a) { r.push_back(n - k + i); sum += x; continue; } else if (x + sum <= 2 * a) { r.push_back(n - k + i); for (int j : r) l.push_back(j); return l; } int begin = i + 1, end = n - k + i, mid; while (begin < end) { mid = (begin + end) >> 1; x = ask(mid); if (a <= sum + x && x + sum <= 2 * a) { r.push_back(mid); for (int j : r) l.push_back(j); return l; } if (a > sum + x) { begin = mid + 1; } else end = mid; } for (int j : r) l.push_back(j); return l; } return {}; } void solve(int n, int k, long long a, int s) { int begin = 1, end = n + 1, mid; while (begin < end) { mid = (begin + end) >> 1; if (ask(mid) < a) { begin = mid + 1; } else end = mid; } vi ans = Solve(end - 1, k, a); if (!ans.empty()) answer(ans); else { ll sum = ask(end); ans.push_back(end); for (int i = 1; i < k; i++) { ans.push_back(i); sum += books[i]; } if (a <= sum && sum <= 2 * a) answer(ans); else impossible(); } } //6 3 20 6 //1 2 3 8 9 10
#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...