Submission #1066393

#TimeUsernameProblemLanguageResultExecution timeMemory
1066393abeotDetecting Molecules (IOI16_molecules)C++14
100 / 100
38 ms5724 KiB
#include "molecules.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
vector<int> find_subset(int l, int u, vector<int> w) {
	// idea: take advantage of the condition about being bounded above by U-L
	// so for given m, it's ok to slide and take w_{i+m} - {w_i} and we'll hit in between due to IVT
	int n = w.size();
	vector<pair<int, int> > p(n);
	for (int i=0; i<n; ++i) p[i] = {w[i], i};
	sort(p.begin(), p.end());
	ll lo = 0, hi = 0;
	int ss = 0;
 
	while (!(lo <= u && l <= hi)) {
		if (ss == n) return vector<int>(0); // bad
		lo += (ll) p[ss].first;
		hi += (ll) p[n-1-ss].first;
		ss++;
	}
	// construct possible
	int next = ss;
	while (lo < l) {
		lo += (ll) p[next].first;
		lo -= (ll) p[next-ss].first;
		next++;
	}
	vector<int> ans(ss);
	for (int i=0; i<ss; ++i) ans[i] = p[next-ss+i].second;
	return ans;
}
#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...