Submission #568157

#TimeUsernameProblemLanguageResultExecution timeMemory
568157definitelynotmeeDetecting Molecules (IOI16_molecules)C++98
69 / 100
4 ms584 KiB
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;

vector<int> find_subset(int l, int u, vector<int> w){
    int sum = 0;
    int n = w.size();
    vector<int> o(n);
    iota(all(o),0);
    sort(all(o),[&](int a, int b){
        return w[a] < w[b];
    });
    int ct = 0;
    for(int i = 0; i < n; i++){
        if(sum+w[o[i]] > u)
            break;
        ct++;
        sum+=w[o[i]];
    }
    if(ct == n && sum < l)
        return{};
    vector<int> resp;
    while(sum < l && ct){
        resp.push_back(o.back());
        sum+=w[o.back()]-w[o[ct-1]];
        o.pop_back();
        ct--;
    }
    if(sum < l || sum > u)
        return {};
    
    for(int i = 0; i < ct; i++)
        resp.push_back(o[i]);
    return resp;
}
#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...