Submission #409624

#TimeUsernameProblemLanguageResultExecution timeMemory
409624DBPhoenixDetecting Molecules (IOI16_molecules)C++17
100 / 100
55 ms5580 KiB
#include <bits/stdc++.h>

using namespace std;

#include "molecules.h"

std::vector<int> find_subset(int l, int u, vector<int> w) {
    int n = w.size();

    vector<pair<int, int>> sorted(n);

    for (int i = 0; i < n; i++) sorted[i] = make_pair(w[i], i);

    sort(sorted.begin(), sorted.end());

    int length = 0;
    long long sum = 0;
    for (; length < n; length++)
    {
        if (sum + sorted[length].first <= u) {
            sum += sorted[length].first;
        } else break;
    }

    vector<int> result(length);

    for (int i = 0; i < length; i++)
        result[i] = sorted[i].second;

    if (sum >= l)
        return result;

    for (int i = length - 1; i >= 0; i--)
    {
        sum -= w[result[i]];
        result[i] = sorted[n - length + i].second;
        sum += w[result[i]];

        if (sum >= l)
            return result;
    }

    return std::vector<int>(0);
}
#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...