제출 #981687

#제출 시각아이디문제언어결과실행 시간메모리
981687OAleksaA Difficult(y) Choice (BOI21_books)C++14
25 / 100
1 ms852 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; const int N = 1e5 + 69; long long was[N], sum; void solve(int n, int k, long long a, int s) { int l = 1, r = n, lst = n + 1; vector<int> ans; for (int i = 1;i <= k;i++) { if (!was[i]) was[i] = skim(i); sum += was[i]; } if (sum > 2 * a) impossible(); else if (sum >= a && sum <= 2 * a) { for (int i = 1;i <= k;i++) ans.push_back(i); answer(ans); } sum = 0; for (int i = n, j = 0;j < k;i--,j++) { if (!was[i]) was[i] = skim(i); sum += was[i]; } if (sum < a) impossible(); else if (sum >= a && sum <= 2 * a) { for (int i = n,j = 0;j < k;i--,j++) ans.push_back(i); answer(ans); } sum = 0; while (l <= r) { int mid = (l + r) / 2; long long b = 0; if (was[mid] > 0) b = was[mid]; else b = skim(mid); was[mid] = b; if (b >= a) { lst = mid; r = mid - 1; } else l = mid + 1; } assert(lst > k); if (lst != n + 1) { for (int i = 1;i <= k - 1;i++) { if (!was[i]) was[i] = skim(i); sum += was[i]; } sum += was[lst]; if (sum >= a && sum <= 2 * a) { for (int i = 1;i <= k - 1;i++) ans.push_back(i); ans.push_back(lst); answer(ans); } } n = lst - 1; assert(n >= k); assert(was[n] < a && was[n] > 0); sum = 0; for (int i = n, j = 0;j < k;j++,i--) { assert(was[i] > 0); sum += was[i]; } int ptr = n, d = 0; while (d < k) { sum -= was[ptr]; sum += was[n - ptr + 1]; ptr--; d++; if (sum >= a && sum <= 2 * a) break; } for (int i = 1;i <= d;i++) ans.push_back(i); for (int i = n - k + 1;i <= ptr;i++) ans.push_back(i); assert(sum >= a && sum <= 2 * a); 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...