This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<ll> vl;
const int MAXN = 1e5 + 100;
int n, k, s;
ll a;
unordered_map<int, ll> saved;
ll get (int i) {
if (saved[i] > 0)return saved[i];
saved[i] = skim(i);
return saved[i];
}
void solve(int N, int K, long long A, int S) {
n = N;
k = K;
a = A;
s = S;
vi ids;
FOR(i, 1, k) {
ids.pb(i);
}
//if (get() {
int le = 1, ri = n;
while (le < ri) {
int mid = (le+ri)/2;
if (get(mid) > a) ri = mid;
else le = mid+1;
}
le = max(le, k);
//if (get(le) <= a) le =
//cout << " le = " << le << endl;
ll cur = 0;
FOR(i, 1, k-1) cur += get(i);
cur += get(le);
if (a <= cur && cur <= 2*a) {
vi ret;
FOR(i, 1, k-1) ret.pb(i);
ret.pb(le);
answer(ret);
return;
}
if (get(le) < a) le = n+1;
FOR(i, max(k+1, le-k), le-1) ids.pb(i);
//}
FOR(i, 0, k) {
ll cur = 0;
vi ret;
FOR(j, 0, i-1) {
cur += get(ids[j]);
ret.pb(ids[j]);
}
FOR(j, (int)ids.size()-(k-i), (int)ids.size()-1) {
cur += get(ids[j]);
ret.pb(ids[j]);
}
if (a <= cur && cur <= 2*a) {
answer(ret);
return;
}
}
//answer(ret);
impossible();
}
/*
15 3 27 40
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
*/
# | 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... |