This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Dost SEFEROĞLU
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
using namespace std;
void solve(int32_t N, int32_t K, long long A, int32_t S) {
vi memory(N+1,0);
auto get = [&](int p) -> int {
if (memory[p]) return memory[p];
return memory[p] = skim(p);
};
int sm = 0;
for (int i=1;i<=K-1;i++) sm+=get(i);
int l = K;
int r = N;
while (l<=r) {
int m = (l+r) >> 1;
if (get(m)+sm >= A) r = m-1;
else l = m+1;
}
if (l<=N && get(l)+sm >= A && get(l)+sm <= 2*A) {
vector<int32_t> v;
for (int j=1;j<=K-1;j++) v.push_back(j);
v.push_back(l);
answer(v);
return;
}
sm+=get(K);
int ptr = K;
while (sm < A) {
if (ptr < 1) {
impossible();
return;
}
sm-=get(ptr);
sm+=get(l-1-(K-ptr));
ptr--;
}
if (sm >= A && sm <= 2*A) {
vector<int32_t> v;
for (int i=1;i<=ptr;i++) v.push_back(i);
for (int j=K-ptr;j>=1;j--) v.push_back((l-1)-j+1);
answer(v);
}
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... |