제출 #1189743

#제출 시각아이디문제언어결과실행 시간메모리
1189743PlayVoltzA Difficult(y) Choice (BOI21_books)C++20
100 / 100
1 ms1176 KiB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

#define pb push_back

void solve(int n, int k, long long a, int s){
	#define int long long
	int sum=0;
	signed low=k-1, high=n+1;
	vector<int> vect(n+1);
	vector<signed> ans, temp;
	for (int i=1; i<=k; ++i)vect[i]=skim(i), sum+=vect[i];
	if (sum>2*a){
		impossible();
		return;
	}
	if (sum>=a){
		for (int i=1; i<=k; ++i)ans.pb(i);
		answer(ans);
		return;
	}
	sum-=vect[k];
	while (low+1<high){
		int mid=(low+high)/2;
		vect[mid]=skim(mid);
		if (sum+vect[mid]>=a)high=mid;
		else low=mid;
	}
	if (high<=n&&sum+vect[high]<=2*a){
		for (int i=1; i<k; ++i)ans.pb(i);
		ans.pb(high);
		answer(ans);
		return;
	}
	for (int i=1; i<=k; ++i)temp.pb(i);
	for (int i=max(k+1, high-k); i<high; ++i)vect[i]=skim(i), temp.pb(i);
	for (int i=k; i<=temp.size(); ++i){
		int sum=0;
		for (int j=i-k; j<i; ++j)sum+=vect[temp[j]];
		if (a<=sum&&sum<=2*a){
			for (int j=i-k; j<i; ++j)ans.pb(temp[j]);
			answer(ans);
			return;
		}
	}
	impossible();
	#undef int
}
#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...