暴力出TLE

P2367 语文成绩

Ziy119 @ 2024-12-14 14:20:34

刚刚从P3397过来的我果断写出TLE代码:

#include<bits/stdc++.h>
#define r 100000000
using namespace std;
int a[r],n,m,x,y,z;
int main(){
    cin.tie(0); 
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(;m--;){
        cin>>x>>y>>z;
        for(int i=x;i<=y;i++)
        a[i]+=z;
    }

    int minn=2<<20;
    for(int i=1;i<=n;i++){
        minn=min(minn,a[i]);
    }
    cout<<minn;
//  //  

    return 0;
} 

P3397暴力AC记录


by _Dayao_ @ 2024-12-14 14:34:29

#include<bits/stdc++.h>
using namespace std;
int a[1000000],n,m,x,y,z;
int main(){ 
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++){
        cin>>x>>y>>z;
        for(int i=x;i<=y;i++)
            a[i]+=z;
    }
    int minn=100000000;
    for(int i=1;i<=n;i++){
        minn=min(minn,a[i]);
    }
    cout<<minn;
    return 0;
}

by _Dayao_ @ 2024-12-14 14:34:42

@Ziy119


by _Dayao_ @ 2024-12-14 14:35:18

@Ziy119最后一个RE了,我也没办法


by Ziy119 @ 2024-12-14 15:11:16

数组开小了。 但加个0就TLE

@ycl220038


|