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>
using namespace std;
#define ff first
#define ss second
/*
4
6 8 8 7
15 17
*/
vector<int> find_subset(int l, int u, vector<int> w){
vector<int> ans;
int n = w.size();
vector<pair<int ,int>> a;
int sum = 0;
for(int i = 0;i < n; i++){
a.push_back({w[i], i});
}
sort(a.begin(), a.end());
set<pair<int, int> > st;
for(int i = 0;i < n; i++){
auto [x, idx] = a[i];
sum+= x;
if(sum >= l and sum <= u){
for(int j = 0;j <= i; j++){
ans.push_back(a[i].ss);
}
return ans;
}else if(sum > u){
int left = sum - u, right = sum - l;
auto it = st.lower_bound({left, -100});
if(it == st.end() or it->ff > right){
continue;
}
it++;
while(it != st.end()){
int j = it->ss;
ans.push_back(a[j].ss);
it++;
}
ans.push_back(a[i].ss);
return ans;
}
st.insert({sum, i});
}
ans.push_back(-1);
return ans;
}
//main(){
// int n; cin >> n;
// vector<int> w(n);
// for(int i = 0;i < n; i++){
// cin >> w[i];
// }
// int l, u; cin >> l >> u;
// vector<int> index = find_subset(l, u, w);
// for(auto j : index){
// cout << j+1 << ' ';
// }
//}
# | 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... |