# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001735 | vjudge1 | 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 "molecules.h"
#include<bits/stdc++.h>
#pragma GCC optimize("-O3")
#define ll int
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pb push_back
#define p_b pop_back
using namespace std;
vl find_subset(ll l, ll u, vl w) {
vl ans;
vector<pll>vect;
for(ll i = 0; i < w.size(); i++)
vect.pb({w[i], i});
sort(all(vect));
ll tl = 0, tr = 0, sum = 0;
while(tl < vect.size())
{
while(tr < vect.size() && sum + vect[tr].f <= u)
{
sum += vect[tr].f;
tr++;
if(l <= sum && sum <= u)
{
for(ll j = tl; j < tr; j++)
ans.pb(vect[j].s);
return ans;
}
}
if(l <= sum && sum <= u)
{
for(ll j = tl; j < tr; j++)
ans.pb(vect[j].s);
return ans;
}
sum -= vect[tl].f;
tl++;
}
return ans;
}
int main()
{
int n, l, u;
vi w;
cin >> n >> l >> u;
for(int i = 0; i < n; i++)
{
int x;
cin >> x;
w.pb(x);
}
vi res = find_subset(l, u, w);
for(auto u : res)
cout << u << ' ';
cout << "\n";
}