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;
int check(int x, int l, int r) {
return l >= x && x <= r;
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
int n = w.size();
map<int, deque<int>> ids;
for(int i = 0; i < n; i++) {
ids[w[i]].push_back(i);
}
sort(w.begin(), w.end());
vector<int> d(n + 1);
for(int i = 0; i < n; i++) {
for(int j = i; j < n; j++) {
if(u - l >= w[i] - w[j]) {
d[i] = j;
}
}
}
vector<int> ans;
for(int i = 0; i < n; i++) {
multiset<int> ms;
for(int j = i; j < d[i]; j++) {
ms.insert(w[j]);
}
// s + x <= r
// x <= r - s
int s = 0;
int ok = 0;
while(1) {
auto it = ms.upper_bound(u - s);
if(it == ms.begin()) {
ans.clear();
break;
}
it--;
int x = *it;
s += x;
ans.push_back(x);
ms.erase(x);
if(s >= l) {
ok = 1;
break;
}
}
if(ok) {
break;
}
}
vector<int> p;
for(auto it : ans) {
p.push_back(ids[it].front());
ids[it].pop_front();
}
return p;
}/*
signed main(){
for(auto it:find_subset(10, 20, {15, 17,
16, 18}))cout<<it<<" ";
}
*/
# | 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... |