# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40143 | 2018-01-28T07:30:47 Z | tmwilliamlin168 | Detecting Molecules (IOI16_molecules) | C++11 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "molecules.h" using namespace std; typedef long long ll; vector<int> find_subset( int L, int U, vector<int> W){ vector< int > ord( N ), result; for( int i = 0; i < N; ++i ){ ord[ i ] = i; } sort( ord.begin(), ord.end(), [ & ]( int i, int j ){ return W[ i ] < W[ j ]; } ); ll sum = 0; for( int lb = 0, rb = 0; lb < N; ++lb ){ while( sum < L and rb < N ) sum += W[ ord[ rb++ ] ]; if( L <= sum and sum <= U ){ for( int i = lb; i < rb; ++i ) result.push_back(ord[ i ]); break; } if( lb < rb ) sum -= W[ ord[ lb ] ]; } return result; }