0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-18 07:52:00 +00:00
OI-codes/S2OJ/1535/1535.cpp

41 lines
719 B
C++
Raw Normal View History

#include <iostream>
#include <deque>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e6 + 5;
int n, a[N], b[N], ans;
std::deque<int> q;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
for (int i = 1; i <= n; i++) {
while (!q.empty() && b[i] >= b[q.front()]) q.pop_front();
q.push_front(i);
}
for (int i = 1; i <= n; i++) {
while (!q.empty() && q.back() <= i) q.pop_back();
if (!q.empty()) ans = std::max(ans, b[q.back()] - a[i]);
}
cout << ans << endl;
return 0;
}