Submission #32014

#TimeUsernameProblemLanguageResultExecution timeMemory
32014imeimi2000Detecting Molecules (IOI16_molecules)C++14
100 / 100
93 ms6896 KiB
#include "molecules.h"
#include <algorithm>

using namespace std;
typedef long long llong;

struct mole {
	int x, i;
	bool operator<(const mole &p) const {
		return x < p.x;
	}
};

int n;
vector<mole> arr;
llong sum[200001];
vector<int> ret;
vector<int> find_subset(int l, int u, vector<int> w) {
	arr.resize((n = w.size()) + 1);
	arr[0] = { 0, -1 };
	for (int i = 0; i < n; ++i) {
		arr[i + 1] = { w[i], i };
	}
	sort(arr.begin() + 1, arr.end());
	for (int i = 1; i <= n; ++i) {
		sum[i] = sum[i - 1] + arr[i].x;
	}
	for (int i = 1; i <= n; ++i) {
		llong pre, post;
		pre = sum[i];
		post = sum[n] - sum[n - i];
		if (pre < l && post < l) continue;
		if (u < pre && u < post) continue;
		for (int j = 0;; ++j) {
			llong in = sum[j + i] - sum[j];
			if (l <= in && in <= u) {
				for (int k = 1; k <= i; ++k)
					ret.push_back(arr[j + k].i);
				return ret;
			}
		}
	}
	return ret;
}
#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...