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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/*
ifstream cin("txt.in");
ofstream cout("txt.out");
*/
const int NMAX = 1e6;
const long long INF = 1e15;
const int LGMAX = 20;
int N, S;
long long K, d[NMAX + 5], v[NMAX + 5];
int opt[NMAX + 5], lft[NMAX + 5];
int binaryLift[NMAX + 2][LGMAX + 2];
int main()
{
cin >> N >> S >> K;
d[0] = -INF;
d[1] = 0;
for(int i = 2; i <= N; i++)
{
cin >> d[i];
d[i] += d[i - 1];
}
v[0] = 0;
for(int i = 1; i <= N; i++)
{
cin >> v[i];
v[i] += v[i - 1];
}
int j = 0;
for(int i = 1; i <= N; i++)
{
while(j < i && d[i] - d[j] > K)
j++;
opt[i] = j;
lft[i] = j - 1;
binaryLift[i][0] = lft[opt[i]];
}
for(int step = 1; step <= LGMAX; step++)
for(int i = 1; i <= N; i++)
binaryLift[i][step] = binaryLift[binaryLift[i][step - 1]][step - 1];
pair <long long, pair<int, int>> bst = {-1, {0, 0}};
for(int rg = 1; rg <= N; rg++)
{
int s = S, lf = rg;
for(int step = LGMAX; step >= 0; step--)
if(s >= (1 << step))
{
lf = binaryLift[lf][step];
s -= (1 << step);
}
bst = max(bst, {v[rg] - v[lf], {lf, rg}});
}
vector <int> sol;
int curr = bst.second.second;
while(curr > bst.second.first)
{
sol.push_back(opt[curr]);
curr = binaryLift[curr][0];
}
reverse(sol.begin(), sol.end());
cout << (int)sol.size() << '\n';
for(auto it : sol)
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... |