Submission #403290

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

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

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:9:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(int i=0; i<v.size(); i++) v[i] = {w[i], i};
      |                  ~^~~~~~~~~
molecules.cpp:12:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     while(l < v.size()){
      |           ~~^~~~~~~~~~
molecules.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |             if(r+1 < v.size()) sum += v[++r];
      |                ~~~~^~~~~~~~~~
molecules.cpp:15:36: error: no match for 'operator+=' (operand types are 'int' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'})
   15 |             if(r+1 < v.size()) sum += v[++r];