求助dalao们,为什么我排序求最小反而wa了第二个点

P2367 语文成绩

zzf12345666 @ 2023-03-27 19:58:08

import java.util.*;
public class test{
    static int N=500010;
    static int []a=new int[N];
    static int []b=new int[N];
    static int n,p;
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        n=in.nextInt();
        p=in.nextInt();
        for(int i=1;i<=n;i++){
            a[i]=in.nextInt();
        }
        for(int i=1;i<=n;i++){
            insert(i,i,a[i]);
        }
        while(p-->0){
            int l=in.nextInt();
            int r=in.nextInt();
            int x=in.nextInt();
            insert(l,r,x);
        }
        for(int i=1;i<=n;i++){
            b[i]+=b[i-1];
        }
        Arrays.sort(b,1,n);
        System.out.print(b[1]);
    }
    static void insert(int l,int r,int c){
        b[l]+=c;
        b[r+1]-=c;
    }
}

|