#include <bits/stdc++.h>
#include "molecules.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
const int MAX = 2e5 + 2;
ll id[MAX], a[MAX], n;
bool cmp(int x, int y) {
return a[x] > a[y];
}
vector<int> find_subset(int l, int r, vector<int> w) {
n = w.size();
for (int i = 1; i <= n; i++) {
id[i] = i;
a[i] = w[i - 1];
}
sort(id + 1, id + n + 1, cmp);
ll total = 0;
int temp = 0;
for (int i = 1; i <= n; i++) {
total += a[id[i]];
if (total >= l) {
temp = i;
break;
}
}
vector<int> res;
if (temp == 0) return res;
total = 0;
for (int i = n; i >= n - temp + 1; i--) {
res.push_back(id[i] - 1);
total += a[id[i]];
}
for (int i = 0; i < temp; i++) {
if (total >= l && total <= r) return res;
total += a[id[i + 1]] - a[res[i] + 1];
res[i] = id[i + 1];
}
if (total >= l && total <= r) return res;
return {};
}
/*
int main() {
vector<int> res = find_subset(14, 15, {5, 5, 6, 6});
for (auto i : res) cout << i << " ";
}*/
Compilation message (stderr)
molecules.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |