Submission #362827

#TimeUsernameProblemLanguageResultExecution timeMemory
362827saarthakDetecting Molecules (IOI16_molecules)C++14
69 / 100
48 ms5868 KiB
#include <bits/stdc++.h>

struct weights {
	int wt;
	int idx;
};


bool cmp(weights a, weights b) {
	return (a.wt < b.wt);
}


std::vector<int> find_subset(int l, int u, std::vector<int> w) {
	int n = w.size();
	
	
	int total_weight = 0, a = 0;
	std::queue<int> indices;
	
	std::vector<struct weights> wts(n);
	
	for(int i = 0; i < n; i++)
		wts[i] = {w[i], i};
	
	std::sort(wts.begin(), wts.end(), cmp);
	
	int i = 0, j = 0;
	while(i < n && j < n) {
		while(total_weight < l && j < n) {
			total_weight += wts[j].wt;
			indices.push(wts[j++].idx);
		}
		while(total_weight > u && i < n) {
			total_weight -= wts[i++].wt;
			indices.pop();
		}
		if(total_weight >= l && total_weight <= u) break;
	}
	
	if(total_weight < l || total_weight > u) return std::vector<int>();		//no subarray found
	
	std::vector<int> ans(indices.size());
	while(!indices.empty()) {
		ans[a++] = indices.front();
		indices.pop();
	}
	
	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...