Submission #840178

#TimeUsernameProblemLanguageResultExecution timeMemory
840178sleepntsheepDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include <algorithm>
#include <set>
#include <deque>

std::vector<int> find_subset(int l, int u, std::vector<int> w)
{
    std::sort(w, w+n);
    int s = 0, i;
    std::multiset<int> sub;
    std::deque<int> lo, hi;
    for (i = 0; i < (int)w.size(); ++i) if (s + w[i] < l) s += w[i], lo.push_back(w[i]), sub.insert(i); else break;
    for (int j = i; j < (int)w.size(); ++j) hi.push_back(w[j]);
    while (s < l && lo.size() && hi.size())
    {
        int d = hi.front() - lo.front();
        s += d;
        sub.erase(sub.find(lo.front())); sub.insert(hi.front()); hi.pop_front(); lo.pop_front(); 
    }
    if (s < l) return std::vector<int>();
    std::vector<int> result(sub.begin(), sub.end());

    return result;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:7:20: error: 'n' was not declared in this scope
    7 |     std::sort(w, w+n);
      |                    ^