#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
int n, l;
int solve(vector<pi> x){
int ret = 0, cnt = 0;
multiset<int> st;
rep(i, n) if(x[i].fi <= x[i].se){
//we keep the changes and all
st.insert(x[i].se - x[i].fi);
cnt++;
}
ret = max(ret, cnt); //equivalent to a full sweep in one direction
int tot = 0;
for(int i = n - 1; i >= 0; i--){
//we 'extend' to stamp i
tot = l - x[i].fi;
if((l - x[i].fi) <= x[i].se){
cnt++;
if(x[i].se >= (x[i].fi + tot * 2)){ //it is already counted, but we cant sub twice
cnt--;
auto it = st.find(x[i].se - x[i].fi);
st.erase(it);
}
}
while(st.size() && *st.begin() < (tot * 2)){
cnt--;
st.erase(st.begin());
}
ret = max(ret, cnt);
}
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
cin >> n >> l;
vector<pi> x(n);
rep(i, n) cin >> x[i].fi;
rep(i, n) cin >> x[i].se;
int mx = solve(x);
rep(i, n) x[i].fi = l - x[i].fi;
reverse(all(x));
mx = max(mx, solve(x));
cout << mx << endl;
return 0;
}
/*
Things to look out for:
- Integer overflows
- Array bounds
- Special cases
Be careful!
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |