# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
644372 | vladislav11 | Detecting Molecules (IOI16_molecules) | C++14 | 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;
vector<int> find_subset ( int l, int r, vector<int> w )
{
vector<int> old = w;
sort( w.begin(), w.end(), greater<int>() );
vector<int> a, b;
for ( auto& el : w )
{
if ( l >= el )
{
l -= el;
r -= el;
a.push_back(el);
}
else
b.push_back(el);
}
/*for ( auto& el : a )
cout << el << ' ';
cout << '\n';
for ( auto& el : b )
cout << el << ' ';
cout << '\n';*/
if ( b.size() && b.back() <= r )
{
l -= b.back();
r -= b.back();
a.push_back( b.back() );
b.pop_back();
}
//cout << "! " << l << ' ' << r << '\n';
if ( 0 < l || r < 0 )
return {};
vector<int> ans;
multiset<int> mst( a.begin(), a.end() );
/*for ( auto& el : mst )
cout << el << ' ';
cout << '\n';*/
for ( int i=0; i<old.size(); i++ )
if ( mst.count( old[i] ) )
{
mst.erase(mst.find( old[i] ));
ans.push_back(i+1);
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, l, r;
cin >> n >> l >> r;
vector<int> w(n);
for ( auto& el : w )
cin >> el;
for ( auto& el : find_subset( l, r, w ) )
cout << el << ' ';
return 0;
}