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"
using namespace std;
#define pb push_back
#define pi pair<int,int>
#define ll long long
#define mp make_pair
vector<int> find_subset(int l, int u, vector<int> ww) {
int n = ww.size();
vector<ll> w(n);
for(int i =0; i<n ;i++) w[i] = ww[i];
set<pair<int, pair<int,int>>> pos;//val, w, ind
int num_ans = -1;
vector<int> ans;
for(int i = 0; i<n; i++){
//if( cursum + weights[i].w > u) continue;
if(w[i] >=l && w[i] <= u){
return vector<int>(1, i);
}
set<int> ins;
bool won = false;
for(pair<int,pair<int,int>> val : pos){
int num = val.first;
if(num + w[i] >= l && num+w[i] <= u){
num_ans = num;
ans.pb(i);
won = true;
break;
}
if(num + w[i] < l ){
ins.insert(num+w[i]);
}
}
if(won ) break;
pos.insert({w[i], {w[i], i}});
for(int val : ins){
pos.insert({val, {w[i], i}});
}
}
if(num_ans == -1) return vector<int>();
while(num_ans != 0){
pair<int, pi> val = *lower_bound(pos.begin(), pos.end(), mp(num_ans, mp(-1, -1)));
ans.pb(val.second.second);
num_ans = num_ans - val.second.first;
}
sort(ans.begin(), ans.end());
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... |