Submission #741862

#TimeUsernameProblemLanguageResultExecution timeMemory
741862mzvDetecting Molecules (IOI16_molecules)C++17
100 / 100
45 ms4468 KiB
#include <bits/stdc++.h>

#define ccd ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define usaco freopen("(insert).in", "r", stdin);freopen("(insert).out", "w", stdout);

using namespace std;

/* ------------------------ hi lol ------------------------ */

// author : mzv

vector<int> find_subset(int l, int u, vector<int> w) { // array sucks at size (and also i keep getting CE when using int[], idk why :/)
	int k = w.size();
	vector<pair<int,int>>weight;
	for (int i=0;i<k;i++) {
		weight.push_back({w[i],i});
	}
//	for (auto we : weight) {
//		cout << we.first << " " << we.second << endl;
//	}
	sort(weight.begin(),weight.end());
	int idx=0;
	ll sum=0;
	for (int i=0;i<k;i++) {
		sum+=weight[i].first;
		if (sum>u) {
			while (sum>u) {
				sum-=weight[idx].first;
				idx++;
			}
		}
		if (sum>=l&&sum<=u) {
			// done
			vector<int> v;
			for (int x=idx;x<=i;x++) {
				v.push_back(weight[x].second);
			}
			return v;
		}
	}
	// not found
	return {};
}

/*
int main() {
	ccd
//	usaco
//	vector<int> p = find_subset(15, 17, {6, 8, 8, 7}); // 1 2
//	vector<int> p = find_subset(14, 15, {5, 5, 6, 6}); // empty
//	vector<int> p = find_subset(10, 20, {15, 17, 16, 18}); // 0
	for (auto pp : p) {
		cout << pp << " ";
	}
}
*/
/*
two pointer approach
1 3 5 7 9
11 14

1
4
9
16
while --> 15,12 stop!

5,7 noted!
*/
#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...