# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1132205 | lopkus | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define int long long
#include "molecules.h"
using namespace std;
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
vector<pair<int,int>> V;
int n = w.size();
for(int i = 0; i < n; i++) {
V.push_back({w[i], i});
}
sort(V.begin(), V.end());
int i = 0, j = 0;
int x = 0;
while(i < n && j < n) {
if(x >= l && x <= u) {
break;
}
if(x < l && j < n - 1) {
if(j + 1 == n) {
break;
}
j++;
x += V[j].first;
}
else {
x -= V[i].first;
i++;
}
}
vector<int> ans;
if(x >= l && x <= u) {
for(int q = i; q <= j; q++) {
ans.push_back(V[q].second);
}
}
sort(ans.begin(), ans.end());
return ans;
}