This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#ifndef mikevui
// #include "task.h"
//#endif // mikevui
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double dou;
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define MASK(x) (1LL<<(x))
#define BITj(x, j) (((x)>>(j))&1)
template<typename T> bool maximize(T &x, const T &y) {
if (x < y) {x = y; return 1;}
return 0;
}
template<typename T> bool minimize(T &x, const T &y) {
if (x > y) {x = y; return 1;}
return 0;
}
const int maxn = 2e5+5;
int n, l, r;
vector<int> ans;
vector<pii> a;
void solve() {
int j = 0, sum = 0;
//be careful of overflow
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
while (j+1 <= n && r-sum-a[i].fi < 0) {
sum -= a[j++].fi;
}
sum += a[i].fi;
// cout << i << ' ' << j << ' ' << sum << "\n";
if (l <= sum && sum <= r) {
for (int cur = j; cur <= i; cur++) {
ans.pb(a[cur].se);
}
break;
}
}
sort(ans.begin(), ans.end());
}
vector<int> find_subset(int _l, int _r, vector<int> w) {
n = (int)w.size();
l = _l;
r = _r;
for (int i= 0; i < n; i++) {
a.pb({w[i], i});
}
solve();
return ans;
}
#ifdef mikevui
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// #define name "task"
// if (fopen(name".inp", "r")) {
// freopen(name".inp", "r", stdin);
// freopen(name".out", "w", stdout);
// }
int n, l, u;
vector<int> w;
cin >> n >> l >> u;
for (int i= 1; i <= n; i++) {
int x;
cin >> x;
w.pb(x);
}
vector<int> res = find_subset(l, u, w);
for (int x : res ){
cout << x << ' ';
}
}
#endif // mikevui
/*
4 15 17
6 8 8 7
*/
# | 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... |