#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
long long N;
pair<long long, int> W[1 << 18];
long long L, R;
vector<int> solve(int pos) {
long long sum = 0;
long long idx = -1;
for (int i = 0; i < pos; i++) sum += W[i].first;
if (L <= sum && sum <= R) {
idx = 0;
}
else {
for (int i = 1; i <= pos; i++) {
sum -= W[pos - i].first;
sum += W[N - i].first;
if (L <= sum && sum <= R) { idx = i; break; }
}
}
if (idx == -1) return vector<int> {};
vector<int> vec;
for (int i = 0; i < pos - idx; i++) vec.push_back(W[i].second);
for (int i = 0; i < idx; i++) vec.push_back(W[N - 1 - i].second);
sort(vec.begin(), vec.end());
return vec;
}
vector<int> find_subset(int l, int u, vector<int> w) {
N = w.size();
L = l;
R = u;
for (int i = 0; i < N; i++) W[i] = make_pair(w[i], i);
sort(W, W + N);
// CALC1
long long val = 0, cnt = -1;
for (int i = 1; i <= N; i++) {
val += W[i].first;
if (val >= l) { cnt = i; break; }
}
if (cnt == -1) return vector<int>{};
// CALC2
vector<int> V1 = solve(cnt - 1);
vector<int> V2 = solve(cnt);
if (V1.size() >= 1) return V1;
if (V2.size() >= 1) return V2;
return vector<int>{};
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
1 ms |
384 KB |
OK (n = 12, answer = YES) |
3 |
Correct |
1 ms |
256 KB |
OK (n = 12, answer = NO) |
4 |
Correct |
1 ms |
256 KB |
OK (n = 12, answer = NO) |
5 |
Correct |
1 ms |
256 KB |
OK (n = 12, answer = YES) |
6 |
Correct |
1 ms |
256 KB |
OK (n = 12, answer = YES) |
7 |
Correct |
1 ms |
256 KB |
OK (n = 12, answer = YES) |
8 |
Correct |
1 ms |
384 KB |
OK (n = 12, answer = YES) |
9 |
Incorrect |
1 ms |
384 KB |
Contestant can not find answer, jury can |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
1 ms |
256 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |