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 <bits/stdc++.h>
#include "molecules.h"
#pragma GCC optimize("O2,unroll-loops")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define en cin.close();return 0;
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
#define r0 return 0;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> find_subset(int l, int u, vector<int> inp)
{
int n = inp.size();
ll pf[n+1], sf[n+2];
vector<pair<int,int> > w(n);
for(int i = 0;i<n;i++)
w[i]={inp[i],i};
sort(w.begin(),w.end());
pf[0]=sf[n+1]=0;
for(int i = 1;i<=n;i++)
pf[i]=pf[i-1]+w[i-1].fi,
sf[n-i+1]=sf[n-i+2]+w[n-i].fi;
if(pf[n]<l||u<pf[1])
return {};
for(int i = 1;i<=n;i++)
if(l<=pf[i]&&pf[i]<=u)
return {w[i].se};
int k = 1;
while(k<n&&pf[k+1]<l)
k++;
if(sf[n-k+1]<l)
return {};
vector<int> ans(k);
for(int i = 0;i<k;i++)
ans[i]=w[i].se;
ll cur = pf[k];
for(int i = 1;cur<l;i++)
cur-=w[i-1].fi,
cur+=w[n-i].fi,
ans[i-1]=w[n-i].se;
sort(ans.begin(),ans.end());//style points
return ans;
}
# | 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... |