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;
const int N = 1e6 + 2;
int n, dp[21][N];
long long s, k, v[N], d[N], st[N];
int main ()
{
  cin >> n >> s>> k;
  for (int i = 2; i <= n; i++) {
    cin >> d[i];
    d[i] += d[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    v[i] += v[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    st[i] = lower_bound(d + 1, d + n + 1, d[i] - k) - d;
    dp[0][i] = st[st[i]] - 1;
  }
  for (int i = 1; (1 << i) <= s; i++)
    for (int j = 1; j <= n; j++)
      dp[i][j] = dp[i - 1][dp[i - 1][j]];
  long long ans = 0, poz = 0;
  for (int i = 1; i <= n; i++) {
    int x = i;
    for (int j = 0; (1 << j) <= s; j++)
      if (s & (1 << j))
        x= dp[j][x];
    if (ans < v[i] - v[x]) {
      poz = i;
      ans = v[i] - v[x];
    }
  }
  vector<int>list;
  for (int j = 0; j < s && poz; j++) {
      list.push_back(st[poz]);
      poz = dp[0][poz];
  }
  reverse(list.begin(), list.end());
  cout << list.size() << "\n";
  for (auto it : list)
    cout << it << " ";
  return 0;
}
| # | 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... |