Submission #232624

#TimeUsernameProblemLanguageResultExecution timeMemory
232624UserIsUndefinedDetecting Molecules (IOI16_molecules)C++14
100 / 100
68 ms7272 KiB
#include <bits/stdc++.h>
//#include "molecules.h"
using namespace std;



long long presum[200005];




std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    int n = w.size();

    vector<pair<int,int>> v;

    for (int i = 0 ; i < n ; i++){
        v.push_back({w[i], i});
    }

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

    for (int i = 0 ; i < n ; i++){
        if (i == 0)presum[i] = v[i].first;
        else presum[i] = presum[i-1] + v[i].first;
    }


    vector<int> ans;

    for (int i = 1 ; i <= n ; i++){
        if (presum[i-1] > u)continue;
        if (presum[n-1] - presum[n-1-i] < l)continue;

        long long sum = 0;

        for (int j = 0 ; j < i ; j++){
            sum+= v[j].first;
        }


        int x = 0;
        int y = i;
        bool ok = false;
        while((sum < l)&&(y < n)){
            sum+= v[y].first;
            sum-= v[x].first;
            y++;
            x++;
            if (sum >= l)ok = true;
        }

        if (sum >= l)ok = true;

        if (ok){
            for (int j = x ; j < y ; j++){
                ans.push_back(v[j].second);
            }
            return ans;
        }
    }

    return ans;

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