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>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
#include "books.h"
map<int,LLI> M;
LLI query(int i) {
if (M.count(i)) return M[i];
else return M[i] = skim(i+1);
}
void solve(int N,int K,long long int A,int S) {
int i;
LLI s = 0;
for (i = 0; i < K; i++) s += query(i);
if (s > 2*A) impossible();
else if (s >= A) {
vi v;
for (i = 0; i < K; i++) v.pb(i+1);
answer(v);
}
else {
int l = K-1,r = N-1;
while (l < r) {
int m = (l+r+1) / 2;
if (s-query(K-1)+query(m) <= 2*A) l = m;
else r = m-1;
}
if (s-query(K-1)+query(l) >= A) {
vi v;
for (i = 0; i < K-1; i++) v.pb(i+1);
v.pb(l+1);
answer(v);
}
else {
s += query(l)-query(K-1);
for (i = K-2; i >= 0; i--) {
s += query(l-(K-i)+1)-query(i);
if (s >= A) break;
}
if (i < 0) impossible();
else {
int p = i;
vi v;
for (i = 0; i < p; i++) v.pb(i+1);
for (i = l-(K-p)+1; i <= l; i++) v.pb(i+1);
answer(v);
}
}
}
}
# | 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... |