이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pll pair<ll,ll>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl;
#define MP make_pair
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
#define endl "\n"
const ll inf=1e18;
const ll maxn=1e5+5;
ll diff[maxn];
ll d(ll x){
if(diff[x])return diff[x];
return diff[x]=skim(x);
}
void solve(int n, int k, long long A, int s) {
ll sum=0;
vector<int>ans;
rep(i,1,n+1){
if(i<=k)sum+=d(i),ans.pb(i);
}
if(sum>2*A)impossible();
if(sum>=A)answer(ans);
// the sum of the first k elements is def lesser than A
//if >=A and <=2A we would have alr answered
//if >2A its def impossible
//if we find the largest index of element that is lesser than A
ll lo=1,hi=n;
while(lo<hi){
ll mid=(lo+hi+1)>>1;
if(d(mid)<=A)lo=mid;
else hi=mid-1;
}
//lo+1 is more than A, check if >A + <A <=2A
if(lo+1<=n and sum-d(k)+d(lo+1)<=2*A){
ans[k-1]=lo;
answer(ans);
}
//if not uhhh :think
//greedy?
//since lo is like less than A, and everything in the [1,k] is def<A
//going from [1,k] to [2,k]U[lo] will def be <=2A
//but if this continues we might get to >A eventually?
//but as soon as its more than A we are done?
//if it ever gets to >A then we just check its <=2A?
//if we do liddis i dont think we will have chance to exceed 2A???
ll id=0;
while(id<k and lo>0){
if(sum>A){
answer(ans);
}
ans[id]=lo;
sum-=d(id);
sum+=d(lo);
id++;
lo--;
}
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... |