Submission #1358879

#TimeUsernameProblemLanguageResultExecution timeMemory
1358879thesenDetecting Molecules (IOI16_molecules)C++20
9 / 100
0 ms344 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define vbool vector<bool>
#define pairll pair<ll, ll>
#define pb push_back
#define fi first
#define sc second

std::vector<int> find_subset(int L, int U, std::vector<int> W) {
    ll l = L, u = U;

    ll n = W.size();
    vector<pairll> w(n);
    for(ll i = 0; i < n; i++) w[i] = {W[i], i};

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

    ll tot = 0;

    vector<int> emp;
    vector<int> res, res2;
    for(ll i = n-1; i >= 0; i--){
        tot += w[i].fi;
        res.pb(w[i].sc);
        res2.pb(i);
        if(l <= tot && tot <= u){
            return res;
        }
        if(tot > u){
            for(ll j = 0; j < i && j < res.size(); j++){
                tot -= w[res2[i]].fi;
                tot += w[j].fi;

                res[j] = w[j].sc;
                if(l <= tot && tot <= u){
                    return res;
                }
            }
            return emp;
        }
    }
    return emp;
}
#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...