제출 #415120

#제출 시각아이디문제언어결과실행 시간메모리
415120tengiz05A Difficult(y) Choice (BOI21_books)C++17
100 / 100
9 ms1080 KiB
#include <bits/stdc++.h> #include "books.h" using i64 = long long; void solve(int n, int k, i64 A, int s) { std::vector<i64> a(n, -1); auto ask = [&](int i) -> i64 { if (~a[i]) { return a[i]; } else { return a[i] = skim(i + 1); } }; int l = -1, r = n; while (l + 1 < r) { int mid = (l + r) / 2; if (ask(mid) * k > A && ask(mid) * k < 2 * A) { l = mid; break; } else if (ask(mid) * k <= A) { l = mid; } else { r = mid; } } int t = std::max(0, l - k + 1); r = std::min(n - 1, l + k - 1); std::vector<int> ans; i64 sum = 0; for (; t + k - 1 <= r; t++) { ans.clear(); sum = 0; for (int i = 0; i < k; i++) { sum += ask(i + t); ans.push_back(i + t + 1); } if (sum >= A && sum <= 2 * A) { answer(ans); } if (sum > 2 * A) { i64 sum = ask(t + k - 1); ans.clear(); for (int i = 0; i < k - 1; i++) { sum += ask(i); ans.push_back(i + 1); } ans.push_back(t + k); if (sum >= A && sum <= 2 * A) { answer(ans); } } } 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...