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>
#ifndef SKY
#include "molecules.h"
#endif // SKY
using namespace std;
#define ll long long
#define pb push_back
#define N 200010
#define ii pair<ll,int>
#define fs first
#define sc second
ll L,R;
vector<ii>a;
int ktr[N],n;
set<ii>s;
vector<int> find_subset(int l, int u, vector<int> w)
{
n=w.size();
for(int i=0;i<n;i++)
a.pb({w[i],i});
sort(a.begin(),a.end());
ll sum=0;
L=l;R=u;
for(int i=0;i<n;i++)
{
ktr[a[i].sc]=1;
sum+=a[i].fs;
// cout<<i<<" "<<a[i]<<" "<<sum<<endl;
s.insert(a[i]);
if(sum>=L&&sum<=R)
{
vector<int>kq={};
for(int i=0;i<n;i++)
if(ktr[i]==1)
kq.pb(i);
return kq;
}
if(sum>R)
{
ii cc=*s.begin();
s.erase(cc);
ktr[cc.sc]=0;
sum-=cc.fs;
}
if(sum>=L&&sum<=R)
{
vector<int>kq={};
for(int i=0;i<n;i++)
if(ktr[i]==1)
kq.pb(i);
return kq;
}
}
return {};
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
int l,u,n;
vector<int>w;
cin>>l>>u>>n;
for(int i=1;i<=n;i++)
{
int u;
cin>>u;
w.pb(u);
}
vector<int>kq=find_subset(l,u,w);
for(auto u:kq)cout<<u<<" ";
}
#endif
# | 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... |