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"
#define xx first
#define yy second
using namespace std;
typedef long long lint;
vector <int> rez;
vector <pair<int, int>> v;
int n;
int st, dr;
void getRez()
{
sort(v.begin(), v.end());
lint sum = 0;
if(v[0].xx > dr)
return;
for(auto u : v)
sum += u.xx;
if(sum < st)
return;
sum = 0;
int cr = 0;
while(cr < n && sum + v[cr].xx < st)
{
sum += v[cr].xx;
cr ++;
}
cr --;
if(sum + v[cr + 1].xx >= st && sum + v[cr + 1].xx <= dr)
{
for(int i = 0; i <= cr + 1; i ++)
rez.push_back(v[i].yy);
return;
}
int j = n - 1;
for(int i = 0; i <= cr && i < j; i ++, j --)
{
sum -= v[i].xx;
sum += v[j].xx;
if(sum >= st && sum <= dr)
{
for(int x = i + 1; x <= cr; x ++)
rez.push_back(v[x].yy);
for(int x = n - 1; x >= j; x --)
rez.push_back(v[x].yy);
return;
}
}
return;
}
vector <int> find_subset(int l, int u, vector<int> w)
{
st = l;
dr = u;
n = w.size();
for(int i = 0; i < n; i ++)
v.push_back({w[i], i});
getRez();
return rez;
}
# | 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... |