解题思路:
第n个位置的数据 = 第n-1位置的数据 + 两者数据差
注意事项:
参考代码:
import java.util.Scanner; public class C1501 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int N = sc.nextInt(), M = sc.nextInt(); int[] a = new int[N]; int Li = 0, Ri = 0, Ci = 0; for(int i = 0; i < M; i++){ Li = sc.nextInt(); Ri = sc.nextInt(); Ci = sc.nextInt(); //Li比Li的前一个多Ci个 a[Li-1] += Ci; //Ri的后一个比Ri少Ci个 if(Ri < N) a[Ri] -= Ci; } int num = 0; for(int i = 0; i < N; i++){ num += a[i]; System.out.print(num + " "); } } sc.close(); } }
0.0分
0 人评分