# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
853068 | _uros9 | 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 endl '\n'
#define int long long
using namespace std;
const long long longlongmax=9223372036854775807;
const int modul=998244353;
const long long mod = 1e9 + 7;
vector<int> find_subset(int l,int u,vector<int> w){
int n=w.size();
vector<int> rez(0);
vector<pair<int,int>> niz(n);
for(int i=0; i<n; i++)
niz[i]={w[i],i};
sort(niz.begin(),niz.end());
if(niz[0].first>u) return rez;
vector<int> pref(n+1,0);
for(int i=0; i<n; i++){
pref[i+1]=pref[i];
pref[i+1]+=niz[i].first;
}
bool ok=false;
int ll,dd;
pref.push_back(1e15);
/*for(auto x:pref)
cout << x << " ";
cout << endl;*/
for(int i=0; i<n&&!ok; i++){
int ind=lower_bound(pref.begin(),pref.end(),pref[i]+l)-pref.begin();
//cout << pref[i] << " " << pref[ind] << endl;
if(pref[ind]-pref[i]>u) continue;
ok=true;
ll=i;
dd=ind;
}
if(!ok) return rez;
for(int i=ll; i<=dd-1; i++)
rez.push_back(niz[i].second);
/*for(auto x:rez)
cout << x << " ";*/
return rez;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("factory.in","r",stdin);
//freopen("factory.out","w",stdout);
int n,l,u;
cin >> n >> l >> u;
vector<int> w(n);
for(auto&x:w)
cin >> x;
vector<int> rez=find_subset(l,u,w);
for(auto x:rez)
cout << x << " ";
cout << endl;
return 0;
}
/*
abcde
01234
04321 --> 12340
0 1
011
110
*/