是不是Java的原因导致最后一个过不了的,MLE求助
查看原帖
是不是Java的原因导致最后一个过不了的,MLE求助
866144
holo_23楼主2023/10/12 21:47
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),p=sc.nextInt();
        int[] diff=new int[n+2];
        for (int i = 1; i < n+1; i++) {
            diff[i]=sc.nextInt();
        }
        int temp=diff[0];
        for (int i = 1; i < n+2; i++) {
            int temp1=diff[i];
            diff[i]=diff[i]-temp;
            temp=temp1;
        }
        for (int i = 0; i < p; i++) {
            int l=sc.nextInt();
            int r=sc.nextInt();
            int s=sc.nextInt();
            diff[l]+=s;
            diff[r+1]-=s;
        }
        int ans=Integer.MAX_VALUE,temp2=0;
        for (int i = 1; i < n+1; i++) {
            temp2+=diff[i];
            ans=Math.min(temp2,ans);
        }
        System.out.println(ans);
    }
}
2023/10/12 21:47
加载中...