Submission #472911

#TimeUsernameProblemLanguageResultExecution timeMemory
472911Erik_GepardDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include "molecules.h"
#include <bits/stdc++.h>
 
using namespace std;
 
std::vector<int> find_subset(int ll, int uu, std::vector<int> w) {
    long long n=w.size();
    long long l=ll;
    long long u=uu;
    vector<pair<long long, long long> > a(w.size());
    for(long long i=0; i<w.size(); i++){
        a[i].first=w[i];
        a[i].second=i;
    }
    sort(a.begin(), a.end());
    long long sum=0;
    long long j=0;
    long long helyesi=-1, helyesj=-1;
    for(long long i=0; i<n; i++){
        while(j<n && sum+a[j].first<=u){
            sum+=a[j].first;
            j++;
        }
        if(sum>=l){
            for(long long q=i; q<j; q++){
              ans.push_back(a[q].second);
            }
            return ans;
          }
        sum-=a[i].first;
    }
    return vector<int>(0);
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(long long i=0; i<w.size(); i++){
      |                        ~^~~~~~~~~
molecules.cpp:26:15: error: 'ans' was not declared in this scope; did you mean 'abs'?
   26 |               ans.push_back(a[q].second);
      |               ^~~
      |               abs
molecules.cpp:28:20: error: 'ans' was not declared in this scope; did you mean 'abs'?
   28 |             return ans;
      |                    ^~~
      |                    abs
molecules.cpp:18:15: warning: unused variable 'helyesi' [-Wunused-variable]
   18 |     long long helyesi=-1, helyesj=-1;
      |               ^~~~~~~
molecules.cpp:18:27: warning: unused variable 'helyesj' [-Wunused-variable]
   18 |     long long helyesi=-1, helyesj=-1;
      |                           ^~~~~~~