# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
961244 | aminjon__ | 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>
using namespace std;
#define int long long
pair<int,int>w2[200012];
vector<int> find_subset(int l , int r , vector<int> w){
vector <int>result;
int n = w.size();
for(int i = 0;i < n;i++){
w2[i].first = w[i];
w2[i].second = i;
}
int sum = 0 , left = 0 , right = 0;
sort(w2 , w2+n , greater<pair<int,int>>());
while(sum < l && right < n){
sum += w2[right].first;
result.push_back(w2[right].second);
right++;
}
if(sum >= l && sum <= r){
return result;
}
else if(sum < l || right == n){
result.clear();
return result;
}
int last = n-1;
while(last >= right && sum > r && left < right){
sum -= w2[left].first-w2[last].first;
result[left] = w2[last].second;
last--;
left++;
}
if(sum >= l && sum <= r){
return result;
}
result.clear();
return result;
}