Submission #491989

#TimeUsernameProblemLanguageResultExecution timeMemory
491989aciDetecting Molecules (IOI16_molecules)C++14
100 / 100
51 ms3656 KiB
#include "molecules.h"
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pi;

std::vector<int> find_subset(int l, int u, std::vector<int> w) 
{
    vector<int> sol;
    int n = w.size();
    vector<pi> v(n);
    for (int i=0; i<n; i++) v[i] = {w[i], i};

    sort(v.begin(), v.end());
    int j = 0;
    long long sum = 0;
    for (int i=0; i<n; i++)
    {
        while(j < n && sum<l)
        {
            sum += v[j].first;
            j++;
        }
        if(sum>=l && sum<=u) 
        {
            for (int k=i; k<j; k++) sol.push_back(v[k].second);
            //cout << "i: "<<i<<" j: "<<j<<endl;
            return sol;
        }
        else sum -= v[i].first;
    }

    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...