#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;/*
vector <int> find_subset(int l, int u, vector <int> w);
int main() {
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]);
}
*/
vector <int> find_subset(int l, int r, vector <int> w){
sort(w.begin(), w.end());
int n = w.size();
vector <pair<int, int>> pref(n);
pref[0] = {w[0], 0};
for(int i = 1; i < n; i++){
pref[i] = make_pair(pref[i-1].first+w[i], i);
}
int pl = 0, pr = 0;
while(pl < n){
int sum = pref[pr].first-(pl ? pref[pl-1].first : 0);
vector <int> inds;
if(l <= sum && sum <= r){
for(int i = pl; i <= pr; i++){
inds.push_back(pref[i].second+1);
}
return inds;
}
else if(sum > r){
sum -= w[pl];
pl++;
}
else if(sum < l && pr+1 != n){
sum += w[++pr];
}
}
return vector <int> (0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
1 ms |
256 KB |
OK (n = 12, answer = YES) |
3 |
Execution timed out |
1093 ms |
256 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |