WA+RE

P2367 语文成绩

csxx601cjy @ 2024-09-07 08:28:54

#include<bits/stdc++.h> 
using namespace std;
int n,m,a[200001],a1[200001],l,r,f,mi=INT_MAX;
int main(){
    memset(a,0,sizeof(a));
    memset(a1,0,sizeof(a1));
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]-=a[i-1];
    }
    while(m--){
        cin>>l>>r>>f;
        a[l]+=f;
        a[r+1]-=f;
    }
    for(int i=1;i<=n;i++){
        a1[i]=a[i]+a1[i-1];
        mi=min(mi,a1[i]);
    }
    cout<<mi;
    return 0;
}

by xuxingcheng @ 2024-09-07 16:44:00

你的a数组开小了,应该开到 5*10^6


by xuxingcheng @ 2024-09-07 16:50:55


#include<bits/stdc++.h>
using namespace std;
int a[5000005],b[5000005];
int main(){
    int n,m,l,r,c;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i]-a[i-1];
    }
    for(int i=1;i<=m;i++){
        cin>>l>>r>>c;
        b[l]+=c;
        b[r+1]-=c;
    }
    int vmax=INT_MAX;
    for(int i=1;i<=n;i++){
        a[i]=a[i-1]+b[i];
        vmax=min(vmax,a[i]);
    }
    cout<<vmax;
    return 0;
}

|