Submission #399543

#TimeUsernameProblemLanguageResultExecution timeMemory
399543TemmieA Difficult(y) Choice (BOI21_books)C++17
100 / 100
3 ms1152 KiB
#include "books.h" #include <bits/stdc++.h> typedef long long ll; void solve(int n, int k, ll a, int s) { std::vector <ll> vals(n + 1, -1), use; vals[n] = skim(n); if (vals[n] * ll(k) < a) { impossible(); return; } int l = k, r = n; while (l < r) { int mid = (l + r) >> 1; if (vals[mid] == -1LL) vals[mid] = skim(mid); if (ll(k) * vals[mid] >= a) r = mid; else l = mid + 1; } std::vector <int> res; ll sum = 0; for (int i = 1 + l - k; i < l + 1; i++) { if (vals[i] == -1LL) vals[i] = skim(i); res.push_back(i); use.push_back(vals[i]); } for (ll x : use) sum += x; if (a <= sum) { if (sum <= a + a) answer(res); else impossible(); return; } for (int i = l + 1; i < 1 + l + k; i++) { if (vals[i] == -1LL) vals[i] = skim(i); sum += vals[i]; sum -= use[i - l - 1]; res.push_back(i); if (a <= sum && sum <= a + a) { std::vector <int> ans; for (int j = i - l; j < (int)res.size(); j++) { ans.push_back(res[j]); } answer(ans); return; } else if (sum > a + a) { ll newsum = vals[i]; std::vector <int> ans = { i }; for (int j = 1; j < k; j++) { ans.push_back(j); if (vals[j] == -1LL) vals[j] = skim(j); newsum += vals[j]; } if (newsum >= a && newsum <= a + a) { std::sort(ans.begin(), ans.end()); // ??? answer(ans); return; } impossible(); 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...