이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAX_N = 1e5 + 5;
int n, k;
lint tar;
unordered_map<int, lint> val;
bool check() {
lint min_sum = 0;
for (int i = 1; i <= k; i++) min_sum += val[i];
if (min_sum > 2 * tar) return false;
lint max_sum = 0;
for (int i = n - k + 1; i <= n; i++) max_sum += val[i];
if (max_sum < tar) return false;
return true;
}
void solve(int _n, int _k, lint _tar, int _) {
n = _n, k = _k, tar = _tar;
for (int i = 1; i <= k; i++) val[i] = skim(i);
for (int i = n - k + 1; i <= n; i++) val[i] = skim(i);
if (!check()) { impossible(); return; }
deque<int> fixed;
lint sum = 0;
for (int i = 1; i <= k - 1; i++) fixed.push_back(i), sum += val[i];
for (int i = 1; i <= k; i++) {
lint new_sum = sum + val[n - i + 1];
if (tar <= new_sum && new_sum <= 2 * tar) {
vector<int> ans = {n - i + 1};
for (int x : fixed) ans.push_back(x);
answer(ans);
return;
} else if (new_sum < tar) {
sum += val[n - i + 1], sum -= fixed.back();
fixed.push_front(n - i + 1), fixed.pop_back();
continue;
}
int lo = k - i + 1, hi = n - i + 1;
while (lo != hi) {
int mid = (lo + hi) / 2;
if (sum + skim(mid) >= tar) hi = mid;
else lo = mid + 1;
}
vector<int> ans = {lo};
for (int x : fixed) ans.push_back(x);
answer(ans);
return;
}
impossible();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |