Submission #744371

#TimeUsernameProblemLanguageResultExecution timeMemory
744371Dan4LifeDetecting Molecules (IOI16_molecules)C++17
100 / 100
53 ms8240 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
using ll = long long;
const int mxN = (int)2e5+10;
array<ll,2> v[mxN];
ll pre[mxN];

vector<int> find_subset(int L, int R, vector<int> w) {
    int n = (int)w.size();
    for(int i = 0; i < n; i++) v[i]={w[i],i};
    sort(v,v+n);
    for(int i = 0; i < n; i++)
        pre[i+1] = pre[i]+v[i][0];
    vector<int> ans;
    for(int i = 0, j = 0; i < n; i++){
        while(j<=n and pre[j]-pre[i] < L) j++;
        if(j==n+1) break;
        ll sum = pre[j]-pre[i];
        if(L<=sum and sum<=R){
            for(int k = i; k < j; k++)
                ans.push_back((int)v[k][1]);
            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...