This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
mt19937 gnd(time(nullptr));
// #define int long long
vector<int> find_subset(int l, int r, vector<int> w){
int n = w.size();
vector<pair<int, int>> v(n);
for(int i = 0; i < n; i++){
v[i]={w[i], i};
}
sort(v.begin(), v.end());
queue<pair<int, int>> sol;
int aux = 0;
vector<int> ba, bb;
for(int i = 0; i < n; i++){
if(v[i].first <= r && v[i].first >= l){
while(sol.size()) sol.pop();
sol.push(v[i]);
break;
}
if(v[i].first > r) break;
while(aux+v[i].first > r){
ba.push_back(sol.front().first);
bb.push_back(sol.front().second);
aux-=sol.front().first;
sol.pop();
}
aux+=v[i].first;
sol.push(v[i]);
if(aux >= l) break;
int fal = l-aux;
auto it = lower_bound(ba.begin(), ba.end(), fal);
if(it == ba.end()) continue;
int pos = it-ba.begin();
if(aux+ba[pos] <= r){
aux+=ba[pos];
sol.push({ba[pos], bb[pos]});
break;
}
}
if(aux < l || aux > r){
while(sol.size()) sol.pop();
}
vector<int> ans;
while(sol.size()){
ans.push_back(sol.front().second);
sol.pop();
}
if(ans.size()) sort(ans.begin(), ans.end());
return ans;
}
# | 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... |