이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
#define pb push_back
typedef long long int ll;
//bin search for 17
//then take prefix 10 and suffix 10
//in total 38 queries
ll a[111111];
ll ask(int x){
if(a[x])return a[x];
else return a[x] = skim(x);
}
void solve(int n, int k, ll A, int s) {
int l = 1,r = n;
while(r>=l){
int mid = (l+r)/2;
if(ask(mid)<A)l=mid+1;
else r=mid-1;
}
ll sum = 0;
for(int i=1;i<=k;i++)sum+=ask(i);
vector<int>ans; //take k smallest elements
if(sum>2*A)impossible();
else if(sum>=A){
for(int i=1;i<=k;i++)ans.pb(i);
answer(ans);
return;
}
//cout<<l<<'\n';
if(l<=n && l>=k){ //take k-1 smallest elements and l if l exists
sum = 0;
for(int i=1;i<k;i++)sum+=ask(i);
sum+=ask(l);
if(sum>=A && sum<=2*A){
for(int i=1;i<k;i++)ans.pb(i);
ans.pb(l);
answer(ans);
return;
}
}
l = min(l-1,n);
if(l>=k){
for(int i=0;i<=k;i++){ //try all prefix and suffix
sum = 0;
ans.clear();
for(int j=1;j<=i;j++){
sum+=ask(j);
ans.pb(j);
}
int need = k-i;
for(int j=0;j<need;j++){
sum+=ask(l-j);
ans.pb(l-j);
}
if(sum>=A && sum<=2*A){
answer(ans);
return;
}
}
}
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... |