제출 #941842

#제출 시각아이디문제언어결과실행 시간메모리
941842LCJLYA Difficult(y) Choice (BOI21_books)C++14
0 / 100
1 ms1112 KiB
#include <bits/stdc++.h>

#include "books.h"

using namespace std;

//code
//skim() impossible() answer({});
#include <bits/stdc++.h>
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;

void solve(int n, int k, long long a, int s) {
	long long memo[n+5];
	memset(memo,-1,sizeof(memo));
	long long hold=skim(n);
	vector<int>v;
	if(hold>=a){
		long long cnt=0;
		long long cnt2=0;
		for(int x=1;x<=k;x++){
			memo[x]=skim(x);
			cnt2+=memo[x];
		}
		
		int l=1;
		int r=n;
		int best=r;
		int mid;
		while(l<=r){
			mid=(l+r)/2;
			long long take=skim(mid);
			if(take>=a){
				best=r;
				r=mid-1;
			}
			else l=mid+1;
		}
		
		vector<int>v2;
		for(int x=1;x<=k+(best<=k);x++){
			if(x==best) continue;
			if(memo[x]!=-1) cnt+=memo[x];
			else{
				memo[x]=skim(x);
				cnt+=memo[x];
			}
			v2.push_back(x);
		}
		v2.push_back(best);
		
		cnt+=skim(best);
		if(cnt<=2*a){
			answer(v2);
			return;
		}		
		n=best-1;
	}
	long long counter=0;
	vector<pair<long long,long long>>cur;
	for(int x=1;x<=k;x++){
		cur.push_back({memo[x],x});
		counter+=cur.back().first;
	}
	
	int ptr=n;
	//show(counter,counter);
	if((n<=k&&counter<a)||counter>2*a){
		impossible();
		return;
	}
	
	while(counter<a&&!cur.empty()){
		counter+=skim(ptr);
		v.push_back(ptr);
		ptr--;
		counter-=cur.back().first;
		cur.pop_back();
	}
	if(counter>=a){
		for(auto it:cur) v.push_back(it.second);
		answer(v);
		return;
	}
	impossible();
}
//code
#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...