Submission #553219

#TimeUsernameProblemLanguageResultExecution timeMemory
553219sandry24Detecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
int find_subset(int l, int u, int w[], int n, int result[]){
    sort(w, w+n, greater<int>());
    ll sum = 0;
    int ind = 0;
    vector<int> visited(n);
    while(ind != n){
        if(sum + w[ind] < l){
            sum += w[l];
            visited[ind] = 1;
        }
        ind++;
    }
    for(int i = n-1; i >= 0; i--){
        if(!visited[i]){
            sum += w[i];
            visited[ind] = 1;
            break;
        }
    }
    if(sum >= l && sum <= u){
        int m = 0;
        for(int i = 0; i < n; i++){
            if(visited[i]){
                cout << i << ' ';
                result[i] = w[i];
                m++;
            }
        }
        return m;
    }
    return 0;
}

Compilation message (stderr)

molecules.cpp: In function 'int find_subset(int, int, int*, int, int*)':
molecules.cpp:2:18: error: 'greater' was not declared in this scope
    2 |     sort(w, w+n, greater<int>());
      |                  ^~~~~~~
molecules.cpp:2:26: error: expected primary-expression before 'int'
    2 |     sort(w, w+n, greater<int>());
      |                          ^~~
molecules.cpp:2:5: error: 'sort' was not declared in this scope; did you mean 'short'?
    2 |     sort(w, w+n, greater<int>());
      |     ^~~~
      |     short
molecules.cpp:3:5: error: 'll' was not declared in this scope; did you mean 'l'?
    3 |     ll sum = 0;
      |     ^~
      |     l
molecules.cpp:5:5: error: 'vector' was not declared in this scope
    5 |     vector<int> visited(n);
      |     ^~~~~~
molecules.cpp:5:12: error: expected primary-expression before 'int'
    5 |     vector<int> visited(n);
      |            ^~~
molecules.cpp:7:12: error: 'sum' was not declared in this scope
    7 |         if(sum + w[ind] < l){
      |            ^~~
molecules.cpp:9:13: error: 'visited' was not declared in this scope
    9 |             visited[ind] = 1;
      |             ^~~~~~~
molecules.cpp:14:13: error: 'visited' was not declared in this scope
   14 |         if(!visited[i]){
      |             ^~~~~~~
molecules.cpp:15:13: error: 'sum' was not declared in this scope
   15 |             sum += w[i];
      |             ^~~
molecules.cpp:20:8: error: 'sum' was not declared in this scope
   20 |     if(sum >= l && sum <= u){
      |        ^~~
molecules.cpp:23:16: error: 'visited' was not declared in this scope
   23 |             if(visited[i]){
      |                ^~~~~~~
molecules.cpp:24:17: error: 'cout' was not declared in this scope
   24 |                 cout << i << ' ';
      |                 ^~~~