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"
struct masivs{int val;int poz;};
masivs ab[1000006];
using namespace std;
int i,j,k,n,m,sum,pref[1000006],suff[1000006];
vector<int> xx;
vector<int> xcur,xnew;
list<int> vv;
bool c1(masivs maz,masivs liel)
{
if (maz.val==liel.val)
{
return maz.poz<liel.poz;
}
return maz.val>liel.val;
}
vector<int> find_subset(int l, int u, vector<int> w)
{
n=w.size();
i=0;
while (i<n)
{
ab[i].val=w[i];
ab[i].poz=i;
i++;
}
sort(ab,ab+n,c1);
pref[0]=ab[0].val;
i=1;
while (i<n)
{
pref[i]=pref[i-1]+ab[i].val;
i++;
}
i=n-1;
while (i>=0)
{
suff[i]=suff[i+1]+ab[i].val;
i--;
}
k=0;
while (k<n)
{
//cout << pref[k] << " " << suff[n-k-1] << "\n";
if (pref[k]>u&&suff[n-k-1]<=l)
{
i=0;
while (i<=k)
{
sum+=ab[i].val;
vv.push_back(ab[i].poz);
i++;
}
j=0;
while (sum>u)
{
sum+=ab[i].val;
vv.push_back(ab[i].poz);
sum-=ab[j].val;
vv.pop_front();
i++;
}
for (int j:vv)
{
xx.push_back(j);
}
return xx;
}
if (pref[k]<=u&&pref[k]>=l)
{
i=0;
while (i<=k)
{
sum+=ab[i].val;
vv.push_back(ab[i].poz);
i++;
}
for (int j:vv)
{
xx.push_back(j);
}
return xx;
}
if (suff[n-k-1]<=u&&suff[n-k-1]>=l)
{
i=n-1;
sum=0;
while (sum<l)
{
sum+=ab[i].val;
xx.push_back(ab[i].poz);
i--;
}
return xx;
}
k++;
}
return vector<int>(0);
}
# | 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... |