Submission #840206

#TimeUsernameProblemLanguageResultExecution timeMemory
840206sleepntsheepDetecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms212 KiB
#include <algorithm>
#include <utility>
#include <set>
#include <deque>

std::vector<int> find_subset(int l, int u, std::vector<int> w)
{
    int n = w.size(), i;
    std::vector<int> rvcord(n);
    {
        std::vector<std::pair<int, int>> incw(n);
        for (int i = 0; i < n; ++i) incw[i] = {w[i], i};
        std::sort(incw.begin(), incw.end());
        for (int i = 0; i < n; ++i) rvcord[i] = incw[i].second;
        std::sort(w.begin(), w.end());
    }
    long long s = 0;
    std::deque<int> lo, hi;
    for (i = 0; i < n; ++i)
        if (s + w[i] <= u) s += w[i], lo.push_back(i);
        else break;
    for (int j = i; j < n; ++j) hi.push_front(j);
    while (s < l && lo.size() && hi.size())
    {
        long long d = w[hi.front()] - w[lo.front()];
        if (d <= 0) break;
        s += d;
        lo.push_back(hi.front());
        hi.pop_front(); lo.pop_front(); 
    }
    if (s < l) return std::vector<int>();
    std::vector<int> result(n);
    for (int i = 0; i < n; ++i) result[i] = rvcord[lo[i]];
    return result;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...