Submission #533028

#TimeUsernameProblemLanguageResultExecution timeMemory
533028safaricolaDetecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms332 KiB
#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;
int L,U,n,a[200010],pre[200010],su[200010];

vector<int> find_subset(int l, int u, vector<int> w) {
    n=w.size();
    for(int i=0; i<n; i++){
        a[i+1]=w[i];
    } 
    sort(a+1, a+n+1);
    for(int i=1; i<=n; i++){
        pre[i]=pre[i-1]+a[i]; 
    }
    for(int i=n; i>=1; i--){
        su[i]=su[i+1]+a[i];
    }
    //for(int i=1; i<=n; i++) cout<<su[i]<<" ";
     //   cout<<endl;
    int low=0, high=n+1;
    while(high - low >= 2)
    {
        int mid = (high + low) / 2;
        if(pre[mid]>l) high = mid;
        else low = mid;
    }
    //printf("%d, %d \n",high, low);
    for(int i=0; i<high; i++){
        //cout<<pre[i]+su[n-high+i+1]<<" "<<(pre[i]+su[n-high+i+1]>=l)<<" "<<(pre[i]+su[n-high+i+1]<=u)<<endl;
        if(pre[i]+su[n-high+i+1]>=l&&pre[i]+su[n-high+i+1]<=u){
            vector<int> v;
            for(int j=1; j<=i; j++){
                v.push_back(j);
            }
            for(int j=n-high+i+1; j<=n; j++){
                v.push_back(j);
            }
            return v;
        }
    }
    return vector<int>(0);
}
#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...