题目链接:1.泡澡 - 蓝桥云课 (lanqiao.cn)
主要应用前缀和方法解决问题
package lanqiao;import java.util.Scanner;/*** 2023/11/29*/
public class lanqiao3898_泡澡 {static final int MAX = (int) 2e5;public static void main(String[] args) {Scanner scan = new Scanner(System.in);int n = scan.nextInt();//洗澡人数long w = scan.nextLong();//热水器容量long[] pre = new long[MAX];while (n-- > 0) {int l = scan.nextInt();//开始时间int r = scan.nextInt();//结束时间int p = scan.nextInt();//用水量pre[l] += p;//前加p,后减p,使得结果前后未变,只有中间结果每位加ppre[r] -= p;}long need = 0;//需要用水量for (int i = 0; i < MAX; i++) {need += pre[i];if (need > w) {//如果所需大于容量,则无法按计划供应热水System.out.println("No");return;//一旦输出,结束程序}}System.out.println("Yes");}
}
2 5
1 3 3
2 3 3
No进程已结束,退出代码为 0