| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 134605 | ckodser | Detecting Molecules (IOI16_molecules) | C++14 | 142 ms | 17888 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "molecules.h"
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
#define ld long double
using namespace :: std;
const ll maxn=2e5+500;
const ll inf=1e9+900;
ll pr[maxn];
ll sa[maxn];
vector<int> find_subset(int l, int r,vector<int> W) {
    vector<pii> w;
    for(ll i=0;i<W.size();i++){
	w.pb(mp(W[i],i));
    }		
    sort(w.begin(),w.end());
    ll n=w.size();
    pr[0]=w[0].F;
    for(ll i=1;i<n;i++){
	pr[i]=pr[i-1]+w[i].F;
    }
    sa[n-1]=w[n-1].F;
    for(ll i=n-2;i>=0;i--){
	sa[i]=sa[i+1]+w[i].F;
    }
    vector<int> ans;
    for(ll t=1;t<=n;t++){
	if(l<=pr[t-1] && pr[t-1]<=r){
	    for(ll i=0;i<t;i++){
		ans.pb(w[i].S);
	    }
	    sort(ans.begin(),ans.end());
	    return ans;
	}
	if(l<=sa[n-t] && sa[n-t]<=r){
	    for(ll i=n-t;i<n;i++){
		ans.pb(w[i].S);
	    }
	    sort(ans.begin(),ans.end());
	    return ans;
	}
	if(pr[t-1]<l && r<sa[n-t]){
	    ll sum=pr[t-1];
	    set<ll> hast;
	    set<ll> nist;
	    for(ll i=0;i<t;i++)hast.insert(i);
	    for(ll i=t;i<n;i++)nist.insert(i);
	    while(sum<l){
		auto it=(hast.begin());
		sum-=(w[*it].F);
		hast.erase(it);
		
		auto ip=(nist.end());
		ip--;
		sum+=(w[*ip].F);
		nist.erase(ip);
		hast.insert(*ip);
	    }
	    for(auto e:hast){
		ans.pb(w[e].S);
	    }
	    sort(ans.begin(),ans.end());
	    return ans;
	}
    }
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
