Submission #1128889

#TimeUsernameProblemLanguageResultExecution timeMemory
1128889test00A Difficult(y) Choice (BOI21_books)C++20
100 / 100
0 ms412 KiB
#include "bits/stdc++.h" #include "books.h" //#define int long long using namespace std; #define all(v) v.begin(),v.end() #define sz(v) (int)v.size() map<int,long long> Cache; int S; long long ask(int ind){ if(Cache.count(ind)) return Cache[ind]; Cache[ind]=skim(ind); assert(sz(Cache)<=S); return Cache[ind]; } void solve(int n, int k, long long A, int s) { S=s; vector<long long> ilk; for(int i=1;i<=k;i++) ilk.push_back(ask(i)); long long summ=accumulate(all(ilk),0LL); if(summ>2*A){ impossible(); return; } if(summ>=A){ vector<int> lol; for(int i=1;i<=k;i++) lol.push_back(i); answer(lol); return; } int l=k,r=n,idx=n+1; while(l<=r){ int mid=(l+r)/2; if(ask(mid)<A) l=mid+1; else { r=mid-1; idx=mid; } } l=idx-1; if(l+1<=n){ long long res=ask(l+1); for(int i=0;i<k-1;i++) res+=ilk[i]; if(res>=A && res<=2*A){ vector<int> lol; for(int i=1;i<k;i++) lol.push_back(i); lol.push_back(l+1); answer(lol); return; } } for(int i=l;i>k;i--){ summ-=ilk.back(); ilk.pop_back(); summ+=ask(i); if(summ>=A && summ<=2*A){ vector<int> lol; for(int j=1;j<=sz(ilk);j++) lol.push_back(j); for(int j=i;j<=l;j++) lol.push_back(j); answer(lol); return; } if(ilk.empty()){ impossible(); return; } } impossible(); return; } /* void _(){ } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); int tc=1;//cin >> tc; while(tc--) _(); }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...