Submission #1203936

#TimeUsernameProblemLanguageResultExecution timeMemory
1203936arkanefuryDetecting Molecules (IOI16_molecules)C++20
Compilation error
0 ms0 KiB
#include "molecules.h"
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
    int n = w.size();
    int ans = 0;
    vector<pair<int, int>>v;
    int mn = 0;
    for(int i = 0; i < n; i ++)v.push_back({w[i], i});
    sort(v.begin(), v.end());
    int ans = 0;
    vector<int>ko;
    for(int i = 0; i < n; i ++){
        ans += v[i].first;
        while(ans > u)ans -= v[mn].first, mn ++;
        if(ans >= l){
            for(int j = mn; j <= i; j ++)ko.push_back(j);
            return ko;
        }
    }
    ko.clear();
    return ko;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:10:9: error: redeclaration of 'int ans'
   10 |     int ans = 0;
      |         ^~~
molecules.cpp:5:9: note: 'int ans' previously declared here
    5 |     int ans = 0;
      |         ^~~
molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~