Submission #748226

#TimeUsernameProblemLanguageResultExecution timeMemory
748226amirhoseinfar1385A Difficult(y) Choice (BOI21_books)C++17
100 / 100
1 ms296 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; long long n,k,a,s; void solve(int N, int K, long long A, int S) { n=N; k=K; a=A; s=S; vector<long long>all; vector<int>res; long long sum=0; for(int i=1;i<=k;i++){ all.push_back(skim(i)); sum+=all.back(); res.push_back(i); } if(sum>2*a){ impossible(); } if(sum>=a){ answer(res); } int low=0,high=n+1,mid; while(high-low>1){ mid=(high+low)>>1; if(skim(mid)>=a){ high=mid; } else{ low=mid; } } long long fake=0; if(high!=n+1){ sum-=all.back(); fake=skim(high); sum+=fake; if(sum>=a&&sum<=2*a){ res.pop_back(); res.push_back(high); answer(res); } sum-=fake; sum+=all.back(); } vector<long long>all2,res2; long long sum2=0; for(int i=max(low-k+1,1ll);i<=low;i++){ all2.push_back(skim(i)); res2.push_back(low); sum2+=all2.back(); } if(sum2<a){ impossible(); } while(sum<a) { sum-=all.back(); all.pop_back(); sum+=all2.back(); all2.pop_back(); res.pop_back(); } int now=low; while((int)res.size()<k){ res.push_back(low); res2.push_back(low); low--; } answer(res); }

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:66:9: warning: unused variable 'now' [-Wunused-variable]
   66 |     int now=low;
      |         ^~~
#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...