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>
#define F first
#define S second
#define pb push_back
#define ll long long
using namespace std;
vector<int> find_subset(int l, int u, vector<int> w) {
int n=w.size(), x=0;
ll ans=0;
pair<ll, int> p[n];
bool f[n];
memset(f, 0, sizeof(f));
for (int i=0; i<n; i++)p[i]={w[i], i};
sort(p, p+n);
while(x<n&&ans+p[x].F<l)f[x]^=1,ans+=p[x++].F;
if(x<n&&ans+p[x].F>=l&&ans+p[x].F<=u){
vector<int> Ans;
for (int j=0; j<=x; j++)Ans.pb(p[j].S);
sort(Ans.begin(), Ans.end());
return Ans;
}
// cout<<'\n';
// for (int i=0; i<n; i++)cout<<f[i]<<" ";
// cout<<"\nAAAAA\n";
for (int i=x-1; i>=0; i--){
f[i+n-x]^=1; f[i]^=1;
ans+=p[i+n-x].F-p[i].F;
if(ans>=l&&ans<=u){
vector<int> Ans;
for (int j=0; j<n; j++)if(f[j])Ans.pb(p[j].S);
sort(Ans.begin(), Ans.end());
return Ans;
}
}
return vector<int>(0);
}
//int main() {
// int n, l, u;
// assert(3 == scanf("%d %d %d", &n, &l, &u));
// vector<int> w(n);
// for (int i = 0; i < n; i++)
// assert(1 == scanf("%d", &w[i]));
// vector<int> result = find_subset(l, u, w);
//
//
// printf("%d\n", (int)result.size());
// for (int i = 0; i < (int)result.size(); i++)
// printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
//}
/*
4 15 17
6 8 8 7
4 14 15
5 5 6 6
4 10 20
15 17 16 18
*/
# | 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... |