#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
long long n, L; cin >> n >> L;
vector<int> forward(n+1, 0);
vector<int> time(n+1, 0);
long long ostatni_od_startu = 0;
for (long long i = 1; i <= n; i++){
cin >> forward[i];
forward[i] = forward[i] - ostatni_od_startu;
ostatni_od_startu += forward[i];
} forward[0] = L - ostatni_od_startu;// startujemy z zera wiec tego nawet nie loczymy???
for (long long i = 1; i <= n; i++){
cin >> time[i];
}
// sprawdzic ile sie uzyska idac do przodu
// ile do tylu
// prefiks i sufiks z tym jak by wziac ity element i sie cofnac na 0
//vector<int> pomiedzy(n, 1);
long long res = 0;
for (long long r_fwrd = 0; r_fwrd <= n; r_fwrd++){
// ruchy do przodu, reszta do tylu
vector<bool> zebrane(n+1, 0); zebrane[0] = 1;
long long v = 0;
long long t = 0;
long long aktual = 0;
for (long long i = 0; i <= r_fwrd; i++){
v++;
if(v > n){
v = 0;
}
t += forward[v];
if(t <= time[v] && zebrane[v] == 0){
aktual++;
zebrane[v] = 1;
}
// cout << v << ' ' << (t <= time[r_fwrd]) << '\n';
}
long long r_back = n - r_fwrd;
for (long long i = 0; i < 2*r_back; i++){
t += forward[v];
v--;
if(v < 0){
v = n;
}
if(t <= time[v] && zebrane[v] == 0){
aktual++;
}
}
// cout << r_fwrd << ' ' << aktual << '\n';
res = max(aktual, res);
}
for (long long r_fwrd = 0; r_fwrd <= n; r_fwrd++){
vector<bool> zebrane(n+1, 0); zebrane[0] = 1;
long long v = 0;
long long t = 0;
long long aktual = 0;
long long r_back = n - r_fwrd;
for (long long i = 0; i < r_back; i++){
t += forward[v];
v--;
if(v < 0){
v = n;
}
if(t <= time[v] && zebrane[v] == 0){
aktual++;
// cout << v << '\n';
zebrane[v] = 1;
}
}
for (long long i = 0; i < 2*r_fwrd; i++){
v++;
if(v > n) v = 0;
t += forward[v];
if(t <= time[v] && zebrane[v] == 0){
aktual++;
zebrane[v] = 1;
// cout << v << '\n';
}
//cout << v << ' ' << (t <= time[r_fwrd]) << '\n';
}
// cout << r_fwrd << ' ' << aktual << '\n';
res = max(aktual, res);
}
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |