# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1147638 | gulmix | Detecting Molecules (IOI16_molecules) | C++20 | 0 ms | 0 KiB |
#include "molecules.h"
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define oset tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
vector<int> find_subset(int l, int r, vector<int> &w){
vector<pair<int, int>> a(w.size());
for(int i = 0; i < w.size(); i++){
a[i] = {w[i], i+1};
}
sort(all(a));
vector<int> ans;
int cur = 0, lx = 0, rx = 0;
while(lx < (int)a.size() && rx < (int)a.size()){
if(cur < l){
cur += a[lx].first;
ans.push_back(a[lx].second);
lx++;
}else if(cur >= l && cur < r){
return ans;
}else if(cur >= r){
cur -= a[rx].first;
rx++;
ans.erase(ans.begin());
}
}
return vector<int>();
}
//int main(){
// ios::sync_with_stdio(false);
// cin.tie(0);
// //ifstream cin("cycle2.in");
// //ofstream cout("cycle2.out");
// vector<int> b = {15, 17, 16, 18};
// vector<int> a = find_subset(10, 20, b);
// for(auto &i: a)cout << i << ' ';
//}