Submission #399535

#TimeUsernameProblemLanguageResultExecution timeMemory
399535TemmieA Difficult(y) Choice (BOI21_books)C++17
45 / 100
2 ms1096 KiB
#include "books.h"
#include <bits/stdc++.h>

typedef long long ll;

void solve(int n, int k, ll a, int s) {
	
	std::vector <ll> vals(n + 1, -1);
	ll sumfirst = 0;
	for (int i = 1; i <= k - 1; i++) {
		vals[i] = skim(i);
		sumfirst += vals[i];
	}
	int l = k + 1, r = n;
	int best = k;
	while (l <= r) {
		int mid = (l + r) >> 1;
		ll now = skim(mid);
		vals[mid] = now;
		ll total = now + sumfirst;
		if (total >= a + a) {
			r = mid - 1;
		} else {
			l = mid + 1;
			best = mid;
		}
	}
	if (best == k && sumfirst + vals[best] > a + a) {
		impossible();
		return;
	}
	if (sumfirst + vals[best] >= a) {
		std::vector <int> ans;
		for (int i = 1; i <= k - 1; i++) ans.push_back(i);
		ans.push_back(best);
		answer(ans);
		return;
	}
	std::vector <int> ans;
	for (int i = 1; i <= k - 1; i++) ans.push_back(i);
	ans.push_back(best);
	std::set <int> have;
	for (int x : ans) have.insert(x);
	ll sum = sumfirst + vals[best];
	int cur = best;
	for (int i = 1 - 1; i <= k - 1 - 1; i++) {
		sum -= vals[ans[i]];
		have.erase(ans[i]);
		int nw = --cur;
		if (have.count(nw)) {
			impossible();
			return;
		}
		have.insert(nw);
		if (vals[nw] == -1LL) vals[nw] = skim(nw);
		sum += vals[nw];
		if (sum >= a) break;
	}
	std::vector <int> put;
	for (int x : have) put.push_back(x);
	answer(put);
	
}
#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...