# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
507438 | YaserFaisal | 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>
using namespace std ;
#define endl "\n"
#define int long long
int MAX = 1e18 , MIN = -1e18 ;
vector < pair < int , int > > v ;
vector < int > an , ran ;
int n , l , u , dif , ans , check = 0 ;
void solve( int x , int sum , int maxi , int mini )
{
if ( l <= sum && sum <= u )
{
check = 1 ;
ran = an ;
}
if ( check || sum > u ) return ;
for ( int i = x ; i < v.size() ; i++ )
{
if ( an.size() && (maxi-mini) > dif ) break ;
an.push_back(v[i].second) ;
solve(i+1,sum+v[i].first,max(maxi,v[i].first),min(mini,v[i].first)) ;
if(check) return ;
an.pop_back() ;
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> l >> u ;
dif = u-l ; ans = -1 ;
for ( int i = 0 ; i < n ; i++ )
{
int w ; cin >> w ;
if ( l <= w && w <= u )
{
ans = i ;
}
if ( w < l ) v.push_back({w,i}) ;
}
if ( ans != -1 ) { cout << 1 << endl << ans << endl ; return 0 ; }
sort(v.begin(),v.end()) ;
solve(0,0,MIN,MAX) ;
cout << ran.size() << endl ;
for ( auto x:ran ) cout << x << " " ;
}