80分

P2367 语文成绩

WEICY123 @ 2024-09-30 21:44:03

#include<bits/stdc++.h>
using namespace std;
int n,a[100001],b[100001],k,ans=INT_MAX;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i]-a[i-1];
    }
    for(int i=1;i<=k;i++){
        int l,r,water;
        cin>>l>>r>>water;
        b[l]+=water;
        b[r+1]-=water;
    }
    for(int i=1;i<=n;i++){
        b[i]=b[i]+b[i-1];
    }
    for(int i=1;i<=n;i++){
        ans=min(ans,b[i]);
    }
    cout<<ans;
}

by yue2012 @ 2024-10-04 17:04:41

n≤5×10 6 , 数组要开5e6+5


|