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>
using namespace std;
using ll=long long;
vector<int> find_subset(int L, int U, std::vector<int> W) {
ll l=L,u=U;
ll n=W.size();
vector<pair<ll,ll>>w(n);
for(int i=0;i<n;i++)w[i]=make_pair(W[i],i);
sort(w.begin(),w.end());
vector<ll>s(n),t(n);
for(int i=0;i<n;i++){
s[i]=w[i].first;
if(i>0)s[i]+=s[i-1];
}
for(int i=n-1;i>=0;i--){
t[i]=w[i].first;
if(i+1<=n-1)t[i]+=t[i+1];
}
vector<int>ans;
int p=0;
for(int i=0;i<=n;i++){
ll ss=0;
if(i>0)ss+=s[i-1];
while(p<n&&ss+t[p]>u)p++;
if(p<n)ss+=t[p];
if(l<=ss&&ss<=u){
for(int j=0;j<i;j++)ans.push_back(w[j].second);
for(int j=p;j<n;j++)ans.push_back(w[j].second);
break;
}
}
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... |