#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define ppii pair<ll, pii>
#define tiii tuple<ll, ll, ll>
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define f first
#define s second
#define pb push_back
const ll N = 5e3+5;
const ll MOD = 1e9+7;
signed main() {
//freopen("in.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, s, k; cin >> n >> s >> k;
vector<ll> a(n);
for (ll i = 1; i < n; i++) {
ll j; cin >> j; a[i] = a[i-1]+j;
}
vector<ll> v(n), psv(n+1);
for (ll i = 0; i < n; i++) cin >> v[i];
psv[0] = v[0];
for (ll i = 1; i < n; i++) {
psv[i] = psv[i-1]+v[i];
}
psv[n] = psv[n-1];
vector<vector<int>> ans(n+1, vector<int>(22, n));
vector<ll> l(n), r(n);
for (ll i = 0; i < n; i++) {
r[i] = upper_bound(a.begin(), a.end(), a[i]+k)-a.begin();
l[i] = lower_bound(a.begin(), a.end(), a[i]-k)-a.begin()-1;
ans[i][0] = r[i];
}
for (ll i = 1; (1<<i) <= s; i++) {
for (ll j = 0; j < n; j++) {
ans[j][i] = ans[ans[j][i-1]][i-1];
}
}
vector<ll> ans2(n);
for (ll i = 0; i < n; i++) {
ll temp = i;
for (ll j = 0; (1<<j) <= s; j++) {
if (s&(1<<j)) {
temp = ans[temp][j];
}
}
temp--;
if (l[i] >= 0) ans2[i] = psv[temp]-psv[l[i]];
else ans2[i] = psv[temp];
}
ll i = max_element(ans2.begin(), ans2.end())-ans2.begin();
vector<ll> v2;
while (s-- && i != n) {
v2.pb(i);
i = r[i];
}
cout << v2.size() << '\n';
for (ll j : v2) cout << j+1 << " ";
}
| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |