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