Submission #744365

#TimeUsernameProblemLanguageResultExecution timeMemory
744365Dan4LifeDetecting Molecules (IOI16_molecules)C++17
100 / 100
48 ms8088 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;
vector<pair<ll,int>> v;
ll pre[mxN];

vector<int> find_subset(int L, int R, vector<int> w) {
    v.clear(); int n = (int)w.size();
    for(int i = 0; i < n; i++) v.push_back({w[i],i});
    sort(all(v)); pre[0]=0;
    for(int i = 0; i < n; i++)
        pre[i+1] = pre[i]+v[i].first;
    vector<int> ans; ans.clear();
    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(v[k].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...