Submission #725594

#TimeUsernameProblemLanguageResultExecution timeMemory
725594HaroldVemenoDetecting Molecules (IOI16_molecules)C++17
100 / 100
51 ms4800 KiB
#include <bits/stdc++.h>

#ifdef GUDEB
    #define D(x) cerr << #x << ": " << (x) << '\n';
    #define ifdeb if(true)
#else
    #define D(x) ;
    #define ifdeb if(false)
#endif

#define all(x) begin(x), end(x)

using namespace std;
using ull = unsigned long long;
using ll = long long;
// #define int ll;

vector<int> find_subset(int l, int u, vector<int> ws) {
    int n = ws.size();
    vector<int> byw(n);
    iota(all(byw), 0);
    sort(all(byw), [&ws](int a, int b){ return ws[a] < ws[b];});

    ll s = 0;
    int be = n;
    int eb = n;
    for(int i = 0; i < n; ++i) s += ws[i];

    while(true) {
        if(s > u) {
            if(be == 0) return {};
            --be;
            s -= ws[byw[be]];
        } else if(s < l) {
            if(eb == be) return {};
            --eb;
            s += ws[byw[eb]];
        } else {
            vector<int> res{};
            for(int i = 0; i < be; ++i) res.push_back(byw[i]);
            for(int i = eb; i < n; ++i) res.push_back(byw[i]);
            return res;
        }
    }
}
#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...