Submission #744355

#TimeUsernameProblemLanguageResultExecution timeMemory
744355Dan4LifeDetecting Molecules (IOI16_molecules)C++17
0 / 100
65 ms65536 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
using ll = long long;
const int mxN = (int)2e5+10;
ll pre[mxN];
/*
4 15 17
6 8 8 7
*/
vector<int> find_subset(int L, int R, vector<int> w) {
    vector<pair<ll,int>> v; v.clear(); int n = sz(w);
    for(int i = 0; i < n; i++) v.pb({w[i],i+1});
    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; i < n; i++){
        int l = i+1, r = n;
        if(pre[n]-pre[i]<L) break;
        while(l<r and l>=i+1){
            int mid = (l+r)/2;
            ll sum = pre[mid]-pre[i];
            if(sum<L) l=mid+1;
            else if(sum>=R) r=mid-1;
            else break;
        }
        if(l<0 or r>n) continue;
        ll sum = pre[l]-pre[i];
        if(L<=sum and sum<=R){
            for(int j = i; j < l; i++) ans.pb(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...