# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124048 | 2019-07-02T12:21:02 Z | Nodir_Bobiev | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
# include <iostream> # include <vector> # include <algorithm> using namespace std; vector< int > find_subset( int l, int u, vector < int > w ) { vector < pair < int, int > > vc; int n = w.size(); for( size_t i = 0; i < n; i ++ )vc.push_back( make_pair( w[i], i) ); sort( vc.begin(), vc.end() ); long long sm = vc[0].first; vector < int > ans={ vc[0].second }; for( int i = 1; i <n; i ++ ){ if( sm + vc[i].first >= u ) break; sm += vc[i].first; ans.push_back( vc[i].second ); } for( int i = ans.size(); i < n; i ++ ){ if( sm >= l ) break; sm += vc[i].first - vc[ ans[i%ans.size()] ].first; ans[i%ans.size()] = vc[i].second; } if( sm < l || u < sm ) ans.clear(); return ans; } int main() { vector < int > ret = find_subset( 14, 15, {5,5,6,6} ); for( auto c: ret) { cout << c << ' '; } return 0; }