#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 lft[NMAX + 5], rgt[NMAX + 5];
int opt[NMAX + 5];
int binaryLift[NMAX + 2][LGMAX + 2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
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;
}
d[N + 1] = INF;
j = N + 1;
for(int i = N; i >= 1; i--)
{
while(i < j && d[j] - d[i] > K)
j--;
rgt[i] = j;
}
for(int i = N; i > 1; i--) {
if(rgt[i] > rgt[i - 1]) {
for(int j = rgt[i] - 1; j > rgt[i - 1]; j--)
rgt[j] = rgt[i];
}
}
for(int i = 1; i <= N; i++)
binaryLift[rgt[i]][0] = lft[i];
for(int step = 1; step <= LGMAX; step++)
for(int i = 1; i <= N; i++)
binaryLift[i][step] = binaryLift[opt[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[opt[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 |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
375 ms |
98028 KB |
Output is correct |
2 |
Correct |
244 ms |
62700 KB |
Output is correct |
3 |
Correct |
256 ms |
71788 KB |
Output is correct |
4 |
Correct |
284 ms |
78444 KB |
Output is correct |
5 |
Correct |
339 ms |
91756 KB |
Output is correct |
6 |
Correct |
450 ms |
122220 KB |
Output is correct |
7 |
Correct |
298 ms |
81004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
428 ms |
97756 KB |
Output is correct |
2 |
Correct |
237 ms |
57964 KB |
Output is correct |
3 |
Correct |
245 ms |
62060 KB |
Output is correct |
4 |
Correct |
354 ms |
89708 KB |
Output is correct |
5 |
Correct |
335 ms |
87040 KB |
Output is correct |
6 |
Correct |
361 ms |
92384 KB |
Output is correct |
7 |
Correct |
583 ms |
119780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |