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>
#include "molecules.h"
using namespace std;
#define ll long long
vector<int> find_subset(int l, int u, vector<int> w){
int n = w.size();
vector<pair<int,int>> W;
for(int i = 0; i < n; ++i){
W.push_back({w[i], i});
}
sort(W.begin(), W.end());
ll pref[n], suf[n];
for(int i = 0; i < n; ++i){
pref[i] = W[i].first;
if(i) pref[i] += pref[i - 1];
}
for(int i = n - 1; i >= 0; --i){
suf[i] = W[i].first;
if(i < n - 1) suf[i] += suf[i + 1];
}
int k = -1;
for(int i = 1; i <= n; ++i){
int p = i - 1;
int s = n - i;
if(pref[p] <= u && suf[s] >= l){
k = i;
break;
}
}
if(k == -1) return {};
int sum = pref[k - 1];
for(int i = k - 1; i < n; ++i){
int plast = (i - k < 0)? 0 : pref[i - k];
sum = pref[i] - plast;
if(sum >= l && sum <= u){
vector<int> ans;
for(int j = i - k + 1; j <= i; ++j){
ans.push_back(W[j].second);
}
sort(ans.begin(), ans.end());
return ans;
}
}
return {};
}
// int32_t main(){
// auto ret = find_subset(15, 17, {6,8,8,7});
// for(auto x : ret) cout << x << " ";
// cout << "\n";
// ret = find_subset(14, 15, {5, 5, 6, 6});
// for(auto x : ret) cout << x << " ";
// cout << "\n";
// ret = find_subset(10, 20, {15, 17, 16, 18});
// for(auto x : ret) cout << x << " ";
// cout << "\n";
// }
# | 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... |