Water Heater(前缀和)

Water Heater

题目描述
We have a water heater, which supplies W liters of hot water per minute.There are N people. The i-th person plans to use Pi liters of hot water per minute boiled by the heater from Time Si to Ti (excluding at Time Ti exactly). As hot water gets cold fast, it cannot be stored.Is it possible to supply hot water to the people according to their plans?
‎我们有一个热水器,每分钟提供W升热水。‎
‎有N个人。第i人计划使用每分钟由加热器煮沸的热水pi升(完全不包括在时间)。由于热水很快变冷,无法储存。‎
‎有可能按照他们的计划向人民提供热水吗?‎
范围
1≤N≤2e5
0<=Si<=Ti<=2e5
1<W
Pi<1e9
输入
N W
S1 T1 P1

Sn Tn Pn
输出
‎如果有可能按计划向人民提供热水,打印Yes:否则,打印No.

代码

#include <iostream>
using namespace std;

const int N=2e5;
long long pre[N];  //注意范围,这里一定要是ll,int会爆 

int main()
{
	int n,w;
	cin>>n>>w;
	while(n--)
	{
		int s,t,p;
		cin>>s>>t>>p;
		pre[s]+=p;
		pre[t]-=p;
	}
	for(int i=1;i<N;i++)
		pre[i]+=pre[i-1];
	for(int i=0;i<N;i++)
	{
		if(pre[i]>w)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值