Submission #659731

#TimeUsernameProblemLanguageResultExecution timeMemory
659731MahdiA Difficult(y) Choice (BOI21_books)C++17
0 / 100
3072 ms300 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; #define F first #define S second #define siz(v) (int)v.size() typedef pair<int, int> pii; typedef long long ll; const int N=1e5+5; int n, k, s; vector<pii>v; vector<int>res; ll a, num[N]; ll skm(int i){ if(num[i]==0) return num[i]=skim(i); return num[i]; } int bin(ll x){ int l=-1, r=n; while(r-l>1){ int m=(r+l)/2; if(skm(m+1)>x) r=m; else l=m; } return l; } void sol(){ vector<int>w; ll sm=0; sort(v.begin(), v.end()); for(int i=0;i<k;++i){ sm+=v[i].F; w.push_back(i); } w.push_back(siz(v)); while(sm<a){ for(int i=0;i<k;++i){ if(w[i]+1!=w[i+1]){ sm-=v[w[i]].F; sm+=v[w[i]+1].F; ++w[i]; break; } } } w.pop_back(); for(int i=0;i<k;++i) w[i]=v[w[i]].S+1; answer(w); } void solve(int N, int K, long long A, int S) { n=N;k=K;a=A;s=S; int x=bin(a/k); ll sm=0, ls=1e18, h; bool z=0; //cout<<"wtf : "<<x<<'\n'; if(x==-1){ vector<int>w; for(int j=1;j<=k;++j){ sm+=skm(j); w.push_back(j); } if(sm<=2*a) answer(w); impossible(); } for(int i=x;i<n && sm<a;++i){ h=skm(i+1); sm+=h; v.push_back({h, i}); if(h-ls>a){ z=1; break; } ls=h; } if(z){ ll hh=h; int j=x+siz(v)-1; sm-=h; for(int i=max(x-k+siz(v)-1, 0);i<x;++i){ h=skm(i+1); sm+=h; v.push_back({h, i}); } if(sm<=a){ sm=hh; vector<int>w; for(int i=1;i<k;++i){ h=skm(i); sm+=h; w.push_back(i); } w.push_back(j); if(sm<=2*a) answer(w); impossible(); } for(int i=max(x-k+1, 0);i<x-k+siz(v)-1;++i){ h=skm(i+1); v.push_back({h, i}); } } for(int i=max(0, x-k+1);i<x;++i){ h=skm(i+1); v.push_back({h, i+1}); } sol(); }
#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...