Submission #108210

#TimeUsernameProblemLanguageResultExecution timeMemory
108210tictaccatDetecting Molecules (IOI16_molecules)C++14
100 / 100
99 ms7928 KiB
#include "molecules.h"

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {

    int n = w.size();

    vector<int> indices(n);
    iota(indices.begin(),indices.end(),0);
    sort(indices.begin(),indices.end(),[&w](int i, int j) {return w[i] < w[j];});
    sort(w.begin(),w.end());

    vector<ll> pre(n+1), suf(n+1);

    ll k;

    for (k = 1; k <= n; k++) {
        pre[k] = pre[k-1] + w[k-1] - w[0];
        suf[k] = suf[k-1] + w[n-k] - w[0];
        if (pre[k] + k*w[0] <= u && suf[k] + k*w[0] >= l) break;
    }

    if (k <= n) {
        for (int i = 0; i <= k; i++) {
            ll val = pre[i] + suf[k-i] + k*w[0];
            if (val >= l && val <= u) {
                vector<int> res;
                for (int j = 0; j < i; j++) res.push_back(indices[j]);
                for (int j = n-1; j >= n-k+i; j--) res.push_back(indices[j]);
                return res;
            }
        }
    }
    

    return std::vector<int>();
}
#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...