C语言,80求调!就差最后一个时间条件没过

P2367 语文成绩

GUSly @ 2024-12-04 19:13:21

int main()
{
    int i,j,k,n,p,x,y,z,min,x2,y2;
    scanf("%d %d",&n,&p);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<p;i++)
    {
        scanf("%d %d %d",&x,&y,&z);
        for(j=x-1;j<=y-1;j++)
        {
            a[j]+=z;
        }
    }
    min=a[0];
    for(i=0;i<n;i++)
    {
        if(a[i]<min)
            min=a[i];
    }
    printf("%d",min);
}

by RAY130830 @ 2024-12-05 21:12:57

#include<bits/stdc++.h>
using namespace std;
int b[5000010],a[5000010],n,p,x,y,z,m=1e9;
int main(){
    cin>>n>>p;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)b[i]=a[i]-a[i-1];
    for(int i=0;i<p;i++){
        cin>>x>>y>>z;
        b[x]+=z,b[y+1]-=z;
    }
    for(int i=1;i<=n;i++){
        a[i]=a[i-1]+b[i];
        if(m>a[i])m=a[i];
    }
    cout<<m;
    return 0;
}

|