# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
875768 | raul2008487 | Detecting Molecules (IOI16_molecules) | C++17 | 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<bits/stdc++.h>
#include "molecules.h"
#define ll long long
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define vl vector<ll>
using namespace std;
bool check(ll cur, ll low, ll high){
return (cur <= high && cur >= low);
}
vector<int> find_subset(int l, int u, vector<int> w) {
vl ans;
vector<pair<ll,ll>> p;
ll i, j, n = w.size(), left = 0, r = 1;
long long sum = w[0];
for(i=0;i<n;i++){
p.pb({w[i], i});
}
sort(all(p));
bool flag = 0;
while(left <= right){
if(check(sum, l, u)){
break;
}
else if(sum > u){
if(left == n){
flag = 1;
break;
}
sum -= p[left].fi;
left++;
}
else if(sum < l){
if(right == n){
flag = 1;
break;
}
sum += p[right].fi;
right++;
}
}
if(flag){
return ans;
}
else{
for(i=left;i<right;i++){
ans.pb(p[i].se);
}
return ans;
}
}