이 제출은 이전 버전의 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;
array<lint, MAX_N> a;
bool check() {
lint min_sum = 0;
for (int i = 1; i <= k; i++) min_sum += a[i];
if (min_sum > 2 * tar) return false;
lint max_sum = 0;
for (int i = n - k + 1; i <= n; i++) max_sum += a[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 <= n; i++) a[i] = skim(i);
if (!check()) { impossible(); return; }
deque<lint> fixed;
lint sum = 0;
for (int i = 1; i <= k - 1; i++) fixed.push_back(i), sum += a[i];
int f = n;
for (int i = k; i <= n; i++) {
lint new_sum = sum + a[i];
if (tar <= new_sum && new_sum <= 2 * tar) {
vector<int> ans = {i};
for (int x : fixed) ans.push_back(x);
answer(ans);
return;
} else if (new_sum > 2 * tar) {
f = i - 1;
break;
}
}
sum += a[f], sum -= a[fixed.back()];
fixed.push_front(f), fixed.pop_back();
for (int i = 2; i <= k; i++) {
for (int j = k - i + 1; j <= f - i + 1; j++) {
lint new_sum = sum + a[j];
assert(new_sum <= 2 * tar);
if (!(tar <= new_sum && new_sum <= 2 * tar)) continue;
vector<int> ans = {j};
for (int x : fixed) ans.push_back(x);
answer(ans);
return;
}
sum += a[f - i + 1], sum -= a[fixed.back()];
fixed.push_front(f - i + 1), fixed.pop_back();
}
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... |