Submission #403282

#TimeUsernameProblemLanguageResultExecution timeMemory
403282Leonardo_PaesDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> find_subset(int ll, int u, vector<int> v){
    vector<int> ans;
    sort(v.begin(), v.end());
    int l = 0, r = 0;
    long long sum = v[0];
    while(l < v.size()){
        if(ll <= sum and sum <= u) break;
        if(sum < ll){
        	if(r+1 < n) sum += v[++r];
          	else break;
        }
        else if(sum > ll) sum -= v[l++];
    }
    if(sum < ll or sum > u) return ans;
    while(l <= r) ans.push_back(l++);
    return ans;
}

int main(){
    vector<int> v = {6, 8, 8, 7};
    vector<int> ans = find_subset(15, 17, v);
    for(int x : ans) cout << x << " ";
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:9:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     while(l < v.size()){
      |           ~~^~~~~~~~~~
molecules.cpp:12:19: error: 'n' was not declared in this scope
   12 |          if(r+1 < n) sum += v[++r];
      |                   ^