80分求助!c++!

P2367 语文成绩

yc123bc @ 2024-01-30 20:36:40

#include<iostream>
const int N=5e6+200+1;
const int M=5e6+1;
int n,p,minn=N,chengji[M],x,y,z;
int main()
{
    scanf("%d%d",&n,&p);
    for(int i=1;i<=n;i++){
        scanf("%d",&chengji[i]);
    }
    for(int i=1;i<=p;i++){
        scanf("%d%d%d",&x,&y,&z);
        for(int j=x-1;j<=y-1;j++){
            chengji[j]+=z;
        }
    }
    for(int i=1;i<=n;i++){
        if(minn>chengji[i]){
            minn=chengji[i];
        }
    }
    printf("%d",minn);
    return 0;  
}

~~最后一个测试点TLE了! ~~


by Luxingguang @ 2024-01-30 20:39:12

明显 TLE

这题应该用差分 @yc123bc


by Luxingguang @ 2024-01-30 20:39:49

时间复杂度O(N^2)


by yc123bc @ 2024-01-30 20:40:02

@gs1234567 谢


by yc123bc @ 2024-01-30 20:41:12

@gs1234567 有道理


by yc123bc @ 2024-01-30 20:42:37

@gs1234567 这题能不能sort啊


by yc123bc @ 2024-01-30 20:43:30

@yc123bc 应该不行


|