#include "molecules.h"
#include <algorithm>
using namespace std;
std::vector<int> find_subset(int L, int U, std::vector<int> W) {
int N = W.size();
vector<pair<long long, int> > V(N);
for (int i = 0; i < N; i++) V[i] = { W[i], i };
sort(V.begin(), V.end());
vector<long long> Left(N + 1), Right(N + 1);
Left[0] = 0;
for (int i = 0; i < N; i++) Left[i + 1] = Left[i] + V[i].first;
Right[N] = 0;
for (int i = N - 1; i >= 0; i--) Right[i] = Right[i + 1] + V[i].first;
reverse(Right.begin(), Right.end());
for (int i = 0; i <= N; i++) {
long long X = L - Left[i];
int Y = lower_bound(Right.begin(), Right.end(), X) - Right.begin();
if (i + Y > N) continue;
if (Left[i] + Right[Y] <= U) {
vector<int> ANS;
for (int j = 0; j < i; j++) ANS.push_back(V[j].second);
for (int j = 0; j < Y; j++) ANS.push_back(V[N - 1 - j].second);
sort(ANS.begin(), ANS.end());
return ANS;
}
}
return { 0 };
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
sum of weights should be in [10..12] but it is 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
0 ms |
256 KB |
OK (n = 12, answer = YES) |
3 |
Incorrect |
0 ms |
256 KB |
sum of weights should be in [307..317] but it is 50 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
sum of weights should be in [10..12] but it is 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
sum of weights should be in [10..12] but it is 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
sum of weights should be in [10..12] but it is 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
sum of weights should be in [10..12] but it is 9 |
2 |
Halted |
0 ms |
0 KB |
- |