是不是Java的原因导致最后一个过不了的,MLE求助

P2367 语文成绩

holo_23 @ 2023-10-12 21:47:59

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);
    }
}

by Hagasei @ 2023-10-12 22:16:28

@holo_23 是的。 jvm 的内存消耗是不用虚拟机的 C++ 的数倍,而空间范围是给 C++ 的


by holo_23 @ 2023-10-12 22:18:22

@Hagasei 谢谢大佬的解答。


|