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;
using ll = long long;
template<class T> bool cmin(T &i, T j) { return i > j ? i=j,1:0; }
template<class T> bool cmax(T &i, T j) { return i < j ? i=j,1:0; }
vector<int> find_subset(int l, int u, vector<int> w) {
int n = int(w.size());
vector<pair<ll,int>> v(n);
for (int i=0;i<n;i++) {
v[i]=make_pair(w[i],i);
}
sort(v.begin(),v.end());
vector<ll> p1(n),p2(n);
p1[0]=v[0].first;
p2[n-1]=v[n-1].first;
vector<int> res;
for (int i=1;i<n;i++) {
p1[i]=p1[i-1]+v[i].first;
}
for (int i=n-2;i>=0;--i) {
p2[i]=p2[i+1]+v[i].first;
}
for (int i=0;i<n;i++) {
if (p1[i]>=l&&p1[i]<=u) {
for (int k=0;k<=i;k++) {
res.push_back(v[k].second);
}
return res;
}
}
for (int i=0;i<n;i++) {
if (p2[i]>=l&&p2[i]<=u) {
for (int k=n-1;k>=i;k--) {
res.push_back(v[k].second);
}
return res;
}
}
for (int i=0;i<n;i++) {
for (int j=i+1;j<n;j++) {
if (p1[i]+p2[j]>=l && p1[i]+p2[j]<=u) {
for (int k=0;k<=i;k++) {
res.push_back(v[k].second);
}
for (int k=j;k<n;k++) {
res.push_back(v[k].second);
}
return res;
}
}
}
return res;
}
/*
* Say I 'overbuilt' and got sum K > U for some prefix [0...i] and suffix [j...n-1]
* Now I want to 'add and subtract' some pair of numbers: that is, add a number which
* wasn't in previously and subtract an old one.
*/
# | 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... |