# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
921331 | H1H | 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>
#define T "Task"
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w){
vector<pair<int, int>> a;
for(int i = 0; i < w.size(); ++i){
a.push_back({w[i], i});
}
sort(a.begin(), a.end(), [](pair<int,int> a1, pair<int,int> a2){
return a1.first > a2.first;
});
vector<int> ans;
long long sum_val = 0;
int id = 0;
while(true){
if(id == a.size())break;
sum_val += a[id].first;
ans.push_back(a[id].second);
if(sum_val >= l && sum_val <= u){
return ans;
}
if(sum_val > u){
sum_val -= a[ans[0]].first;
ans[0] = a[a.size()-1].second;
sum_val += a[ans[0]].first;
if(!(sum_val >= l && sum_val <= u) || id == a.size()-1){
ans.clear();
}
return ans;
}
id += 1;
}
ans.clear();
return ans;
}
void ip(){
// vector<int> a = {15, 17, 16, 18};
// for(auto ai : find_subset(10, 20, a)){
// cout << ai << '\n';
// }
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen(T".INP", "r")){
freopen(T".INP", "r", stdin);
freopen(T".OUT", "w", stdout);
}
// int tt = 1;
//// cin >> tt;
// while(tt--){
// ip();
// }
}