Submission #491984

#TimeUsernameProblemLanguageResultExecution timeMemory
491984collodelDetecting Molecules (IOI16_molecules)C++17
100 / 100
47 ms4956 KiB
#include "molecules.h"
#include <deque>
#include <algorithm>

using namespace std;

using ll = long long;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {

    int N = w.size();
    vector<pair<int, int>> cp(N);
    for(int i = 0; i < N; ++i) cp[i] = {w[i], i};

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

    int i = 0;
    ll sum = 0;
    deque<ll> ans;

    for(int j = 0; j < N; ++j) {
        sum += cp[j].first; // prendi l'elemento
        ans.push_back(cp[j].second);

        // togli gli elementi sbagliati
        while(sum > u) {
            sum -= cp[i].first;
            ans.pop_front();
            i++;
        }

        if(sum >= l) {
            vector<int> ret;
            for(auto &x : ans) ret.push_back(x);


            return ret;
        }
    }

    // nessuna risposta
    return vector<int>();
}
#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...