Submission #374824

#TimeUsernameProblemLanguageResultExecution timeMemory
374824Alex_tz307Detecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h>

using namespace std;

vector<int> find_subset(int l, int r, vector<int> w) {
    int N = w.size();
    vector<pair<int,int>> a(N);
    for(int i = 0; i < N; ++i)
        a[i] = make_pair(w[i], i);
    sort(a.begin(), a.end());
    int st = -1, dr = 0;
    long long sum = 0;
    for(const int &x : w)
        sum += x;
    while(sum < l || sum > r) {
        while(sum > r) {
            if(dr == N)
                return {};
            sum -= a[dr++].first;
        }
        while(sum < l) {
            if(st == N - 1)
                return {};
            sum += a[++st].first;
        }
    }
    if(st < 0 || dr < 0 || st >= N || dr >= N)
        return {};
    vector<int> sol;
    for(int i = 0; i <= st; ++i)
        sol.emplace_back(a[i].second);
    for(int i = dr; i < N; ++i)
        sol.emplace_back(a[i].second);
    return sol;
}
#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...