0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-05 06:38:48 +00:00
OI-codes/USACO/2021.12-Bronze/2/2.cpp

28 lines
544 B
C++

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int n, x, a[100005], b[100005], ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> x;
a[i] -= x;
if (a[i] < 0) {
b[i] = -a[i];
a[i] = 0;
}
if (a[i] > a[i - 1]) ans += a[i] - a[i - 1];
if (b[i] > b[i - 1]) ans += b[i] - b[i - 1];
}
cout << ans << endl;
return 0;
}