Submission #298289

# Submission time Handle Problem Language Result Execution time Memory
298289 2020-09-12T16:55:41 Z sadpotato Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
 
long long sum ;
int x ; 
vector < pair < int , int > > vec ;
vector < int > ans ;

vector<int> find_subset ( int l , int u , vector < int > w ) {
    n = w . size ( ) ;
    for ( int i = 0 ; i < n ; i ++ ) {
        vec . push_back ( { w [ i ] , i } ) ;
    }
    sort ( vec . begin ( ) , vec . end ( ) ) ;
    x = 0 ;
    for ( int i = 0 ; i < n ; i ++ ) {
        while ( x < n && sum < l ) {
            sum += vec [ x ] . first ;
            x ++ ;
        }
        if ( sum >= l && sum <= u ) {
            for ( int j = i ; j <= x ; j ++ ) {
                ans . push_back ( vec [ j ] . second ) ;
            }
            return ans ;
        }
        sum -= vec [ i ] . first ;
    }
    return ans ;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:10:5: error: 'n' was not declared in this scope
   10 |     n = w . size ( ) ;
      |     ^