Editorial for 串一串脆薯2


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: a002

僅供參考

#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main() {

    fast

    int n, t;cin >> n >> t;
    vector<int> c(n+1);
    c[0] = 0;
    for(int i = 1;i <= n;i++) cin >> c[i];
    vector<int> dif(n+1);
    dif[0] = 0;
    for(int i = 1;i <= n;i++) {
        dif[i] = c[i]-c[i-1];
    }

    while(t--) {
        int a, b, x;
        cin >> a >> b >> x;
        b++;
        dif[a] += x;
        if(b <= n) dif[b] -= x;
    }

    int ans = 0;

    for(int i = 1;i <= n;i++) {
        dif[i] += dif[i-1];
        ans = max(ans, dif[i]);
    }

    cout << ans;

    return 0;
}

Comments

There are no comments at the moment.