# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
719979 | vinnipuh01 | 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>
#define int long long
using namespace std;
vector <int> v;
vector<int> find_subset(int l , int u , vector<int> w) {
set <pair<int, int> > st, s;
int sum = 0;
vector <pair<int, int> > ww;
for ( int i = 0; i < w.size(); i ++ )
ww.push_back( { w[ i], i } );
sort( ww.begin(), ww.end() );
if ( ww.front().first > u ) {
vector <int> v;
return v;
}
else if ( ww.front().first <= u && ww.front().first >= l ) {
vector <int> v;
v.push_back( ww.front().second );
return v;
}
for ( int i = 0; i < ww.size(); i ++ ) {
if ( sum + ww[ i ].first <= u )
st.insert( { ww[ i ].first, ww[ i ].second } ), sum += ww[ i ].first;
else
s.insert( { ww[ i ].first, ww[ i ].second } );
}
while ( sum < l ) {
if ( !s.size() )
break;
sum += s.rbegin()->first - st.begin()->first;
st.erase( st.begin() );
st.insert( *s.rbegin() );
s.erase( --s.end() );
}
vector <int> v;
v.clear();
if ( sum < l )
return v;
for ( auto i : st )
v.push_back( i.second );
sort( v.begin(), v.end() );
return v;
}
//main () {
// int l, r;
// cin >> l >> r;
// int n;
// cin >> n;
// int num;
// for ( int i = 1; i <= n; i ++ ) {
// cin >> num;
// v.push_back( num );
// }
// v = find_subset( l, r, v );
// if ( v.size() )
// cout << "YES\n";
// else
// cout << "NO\n";
//}