精选一百道备赛蓝桥杯——5.空调
差分
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int a[100010], t[100010];
int ad[100010], td[100010];
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int ans = 0;
int n; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> t[i];
int z = 0, f = 0;
for(int i = 1; i <= n; i++){
ad[i] = a[i] - a[i-1];
td[i] = t[i] - t[i-1];
if(td[i] - ad[i] > 0) z += td[i] - ad[i];
else f -= td[i] - ad[i];
}
cout << max(z, f);
return 0;
}