#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
//#define TEST
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;
vector<ii> val;
int bs(int l, int r, int x){
int ans = -1;
while (l <= r){
int mid = (l+r)/2;
if (val[mid].fi <= x)
ans = mid, l = mid+1;
else
r = mid-1;
}
return ans;
}
vector<int> find_subset(int l, int r, vector<int> W) {
int n = W.size(), sum = 0;
for (int i = 0; i < n; i++)
val.pb(mp(W[i], i));
sort(val.begin(), val.end());
vector<int> out;
while (true){
n = bs(0, n-1, r-sum);
if (n == -1)
break;
//printf("%d\n", val[n]);
out.pb(val[n].se);
sum += val[n].fi;
if (sum >= l)
break;
}
if (l > sum)
out.clear();
return out;
}
#ifdef TEST
int main() {
freopen("01", "r", stdin);
int n, l, u;
assert(3 == scanf("%d %d %d", &n, &l, &u));
std::vector<int> w(n);
for (int i = 0; i < n; i++)
assert(1 == scanf("%d", &w[i]));
std::vector<int> result = find_subset(l, u, w);
printf("%d\n", (int)result.size());
for (int i = 0; i < (int)result.size(); i++)
printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
}
#endif // TEST
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
488 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
520 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
520 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
3 ms |
520 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
2 ms |
580 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
3 ms |
580 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
18 |
Correct |
4 ms |
600 KB |
OK (n = 100, answer = NO) |
19 |
Correct |
3 ms |
644 KB |
OK (n = 100, answer = YES) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
644 KB |
Contestant can not find answer, jury can |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
488 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
520 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
520 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
3 ms |
520 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
2 ms |
580 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
3 ms |
580 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
18 |
Correct |
4 ms |
600 KB |
OK (n = 100, answer = NO) |
19 |
Correct |
3 ms |
644 KB |
OK (n = 100, answer = YES) |
20 |
Incorrect |
2 ms |
644 KB |
Contestant can not find answer, jury can |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
488 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
520 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
520 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
3 ms |
520 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
2 ms |
580 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
3 ms |
580 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
18 |
Correct |
4 ms |
600 KB |
OK (n = 100, answer = NO) |
19 |
Correct |
3 ms |
644 KB |
OK (n = 100, answer = YES) |
20 |
Incorrect |
2 ms |
644 KB |
Contestant can not find answer, jury can |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
488 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
520 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
520 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
3 ms |
520 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
2 ms |
580 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
3 ms |
580 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
18 |
Correct |
4 ms |
600 KB |
OK (n = 100, answer = NO) |
19 |
Correct |
3 ms |
644 KB |
OK (n = 100, answer = YES) |
20 |
Incorrect |
2 ms |
644 KB |
Contestant can not find answer, jury can |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
488 KB |
OK (n = 1, answer = NO) |
3 |
Correct |
2 ms |
520 KB |
OK (n = 1, answer = YES) |
4 |
Correct |
2 ms |
520 KB |
OK (n = 2, answer = YES) |
5 |
Correct |
3 ms |
520 KB |
OK (n = 2, answer = YES) |
6 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
7 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
8 |
Correct |
2 ms |
520 KB |
OK (n = 3, answer = YES) |
9 |
Correct |
2 ms |
580 KB |
OK (n = 3, answer = YES) |
10 |
Correct |
3 ms |
580 KB |
OK (n = 3, answer = YES) |
11 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
12 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
13 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
14 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
15 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = YES) |
16 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
17 |
Correct |
2 ms |
600 KB |
OK (n = 3, answer = NO) |
18 |
Correct |
4 ms |
600 KB |
OK (n = 100, answer = NO) |
19 |
Correct |
3 ms |
644 KB |
OK (n = 100, answer = YES) |
20 |
Incorrect |
2 ms |
644 KB |
Contestant can not find answer, jury can |
21 |
Halted |
0 ms |
0 KB |
- |