codeforce div2 620 C. Air Conditioner

Here Insert Picture Description
Title tells of a conditioning temperature can be controlled, regardless of heating or cooling are 1 per minute, for n guest has its own acceptable temperature range per person and asked Can you let all customers are satisfied.

Analysis of the subject, we found that we can control the temperature of the air conditioning, the temperature always have a meal point range [mt, m + t] m1 m2 can be expressed in the course of the guests, we want to ensure every guest, we the last to be included in the scope of the guests accepted range, and to ensure that there is a certain temperature to meet the guests, such as to achieve a minimum ratio of the highest to accept guests below, or to the highest attainable meets the minimum accepted by the guests, ensuring to meet guests demand, in part to ensure the rounding unattainable by max and min function, so we do all we can to an acceptable temperature range, choice and service to the next wave of guests.
ac Code

#include<bits/stdc++.h>
using namespace std;
int t[100], low[100], high[100];
int main()
{
	int q;
	cin>>q;
	while(q--)
	{
		int n,m;
		cin>>n>>m;
		 for(int i=1;i<=n;i++)		 
		 	cin >> t[i] >> low[i] >> high[i];
		 	int w=0,flag=0;
		 	int m1=m,m2=m;
		 	for(int i=1;i<=n;i++)
		 	{
		 		m1-=t[i]-w;
		 		m2+=t[i]-w;
		 		if(m1>high[i]||m2<low[i])
		 		{
		 			flag=1;
		 			break;
				 }
		 		m1=max(m1,low[i]);
		 		m2=min(m2,high[i]);
		 		w=t[i];
			 }
		 	if(flag==1)
			 printf("NO\n");
			 else printf("YES\n");
	}
return 0;
}
Published 48 original articles · won praise 17 · views 4461

Guess you like

Origin blog.csdn.net/weixin_45757507/article/details/104345645