youyang123123 @ 2023-01-26 12:55:34
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int p = scanner.nextInt();
int []a = new int[n+2];
//差分数组---保存前后差
int []b = new int[n+2];
for(int i = 1;i<=n;i++){
a[i] = scanner.nextInt();
b[i] = a[i] - a[i-1];
}
while((p--)>0){
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
b[x] += z;
b[y+1] -= z;
}
int min = Integer.MAX_VALUE;
//还原差分数组
for(int i = 1;i<=n;i++){
a[i] = b[i]+a[i-1];
min = Math.min(min,a[i]);
}
System.out.println(min);
}
}
by zzf12345666 @ 2023-02-06 23:37:32
同问,超内存咋办,大佬解决了吗
by KAZHYI @ 2023-02-19 20:13:56
用快读就可以了哦