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;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, L; cin >> n >> L;
vector<int> forward(n+1, 0);
vector<int> time(n+1, 0);
int ostatni_od_startu = 0;
for (int 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 (int 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);
int res = 0;
for (int r_fwrd = 0; r_fwrd <= n; r_fwrd++){
// ruchy do przodu, reszta do tylu
vector<bool> zebrane(n+1, 0); zebrane[0] = 1;
int v = 0;
int t = 0;
int aktual = 0;
for (int 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';
}
int r_back = n - r_fwrd;
for (int 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 (int r_fwrd = 0; r_fwrd <= n; r_fwrd++){
vector<bool> zebrane(n+1, 0); zebrane[0] = 1;
int v = 0;
int t = 0;
int aktual = 0;
int r_back = n - r_fwrd;
for (int 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 (int 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';
}
# | 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... |