Submission #1365438

#TimeUsernameProblemLanguageResultExecution timeMemory
1365438temurbek1371Detecting Molecules (IOI16_molecules)C++20
100 / 100
27 ms4124 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> find_subset(int l, int u, vector<int> w) {
    int n = w.size();
    
    vector<pair<int,int>> a;
    for(int i = 0; i < n; i++) a.push_back({w[i], i});
    sort(a.begin(), a.end());

    int lf = 0, rt = 0;
    long long cs = a[0].first;

    while(lf < n){
        while(rt + 1 < n && cs + a[rt+1].first <= u){
            cs += a[++rt].first;
        }

        if(cs >= l && cs <= u){
            vector<int> ans;
            for(int i = lf; i <= rt; i++)
                ans.push_back(a[i].second);
            return ans;
        }

        cs -= a[lf].first;
        lf++;

        if(lf > rt && lf < n){
            rt = lf;
            cs = a[lf].first;
        }
    }

    return {};
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...