| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1320938 | sameer | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include "molecules.h"
using namespace std;
bool cmp(pair<int, int> x, pair<int, int> y){
return x.first < y.first;
}
vector<int> find_subset(int l, int u, vector<int> w) {
int i, j, k, n = w.size();
pair<int, int> p[n+1];
p[0].first = 0;
for( i = 1; i <= n; i++) p[i].first = w[i-1], p[i].second = i-1;
sort(p+1, p+n+1, cmp);
for( i = 1; i <= n; i++) p[i].first += p[i-1].first;
for( i = 1; i <= n; i++) if(p[i].first <= u && p[n].first-p[n-i].first >= l) break;
vector<int> ans;
if(i > n) return ans;
k = p[i].first;
for( j = 1; j <= i; j++) ans.push_back(p[j].second);
j = 1;
while(k < l){
k -= p[j].first-p[j-1].first; k += p[n+1-j].first-p[n-j].first;
ans[j-1] = p[n+1-j].second;
j++;
} return ans;
}
