제출 #687341

#제출 시각아이디문제언어결과실행 시간메모리
687341AlcabelA Difficult(y) Choice (BOI21_books)C++17
100 / 100
1 ms348 KiB
#include <bits/stdc++.h> #include <books.h> using namespace std; void solve(int n, int k, long long a, int s) { int l = -1, r = n; long long found = -1; while (r - l > 1) { int m = l + (r - l) / 2; long long cur = skim(m + 1); if (cur >= a) { found = cur; r = m; } else { l = m; } } vector<int> ans(k); iota(ans.begin(), ans.end(), 1); if (r + 1 <= k - 1) { impossible(); return; } vector<long long> first(k); long long sumFirst = 0; for (int i = 0; i < k; ++i) { first[i] = skim(i + 1); sumFirst += first[i]; } if (r != n && sumFirst - first.back() + found <= 2 * a) { ans.back() = r + 1; answer(ans); return; } n = r; vector<long long> last(k); long long sumLast = 0; for (int i = n - 1; i >= n - k; --i) { last[n - 1 - i] = skim(i + 1); sumLast += last[n - 1 - i]; } if (sumFirst >= a && sumFirst <= 2 * a) { answer(ans); return; } if (sumLast >= a && sumLast <= 2 * a) { iota(ans.begin(), ans.end(), n - k + 1); answer(ans); return; } if (sumFirst > 2 * a || sumLast < a) { impossible(); return; } long long sum = sumFirst; iota(ans.begin(), ans.end(), 1); for (int i = k - 1; sum < a; --i) { assert(i >= 0); sum -= first[i]; sum += last[k - 1 - i]; ans[i] = n - (k - 1 - i); } answer(ans); }
#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...