目录

精选一百道备赛蓝桥杯5.空调

目录

精选一百道备赛蓝桥杯——5.空调

https://i-blog.csdnimg.cn/direct/5e5dbb7c62044cdabe6109df23caa2c6.png

https://i-blog.csdnimg.cn/direct/7df49b1e31524a47870b47eaf57726ff.png

差分

#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;
}