# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51646 | ernestvw | Detecting Molecules (IOI16_molecules) | C++11 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
return (a.first == b.first ? a.second < b.second : a.first < b.first);
}
vector<int> find_subset(int l, int u, vector<int> w) {
vector<pair<long long, int>> W;
vector<int> V;
int n = (int)w.size();
for(int i = 0; i < n; i++) W.push_back({w[i], i});
sort(W.begin(), W.end(), cmp);
long long mini = 0, maxi = 0;
int I = 0;
for(int i = 0; i < n; i++, I++) {
mini += W[i].first;
maxi += W[n - 1 - i].first;
if((l <= maxi and maxi <= u) or (l <= mini and mini <= u) or (mini <= l and u <= maxi)) break;
}
if(I == n) return V;
int j = 0;
for(j = 0; j <= I; j++)
V.push_back(j);
while(mini < l) {
if(V[I] == n - (j - I)) I--;
mini -= W[V[I]].first;
V[i] = n - (j - I);
mini += W[V[I]].first;
}
for(int i = 0; i < (int)V.size(); i++) V[i] = W[V[i]].second;
return V;
}