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"
//~ #include "grader.cpp"
using namespace std;
#define ll long long
map <int, ll> mp;
ll ask(int idx){
if(mp.count(idx)) return mp[idx];
return mp[idx] = skim(idx);
}
void solve(int N, int K, long long A, int S){
ll sum = 0;
set <int> cur;
for(int i = 1 ; i <= K ; i++){
sum += ask(i);
cur.insert(i);
}
if(A <= sum && sum <= 2 * A){
answer(vector <int>(cur.begin(), cur.end()));
return;
}
if(N == K || sum > 2 * A) impossible();
sum -= ask(K);
int l = K + 1, r = N;
while(l <= r){
int mid = (l + r) / 2;
if(sum + ask(mid) < A) l = mid + 1;
else r = mid - 1;
}
if(l <= N && A <= sum + ask(l) && sum + ask(l) <= 2 * A){
cur.erase(K);
cur.insert(l);
answer(vector <int>(cur.begin(), cur.end()));
return;
}
sum += ask(K);
int g = K, h = l - 1;
for(int i = 0 ; i < K ; i++){
cur.erase(g);
cur.insert(h);
sum -= ask(g);
sum += ask(h);
if(A <= sum && sum <= 2 * A){
answer(vector <int>(cur.begin(), cur.end()));
return;
}
g--;
h--;
}
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... |