Illegal or Not?

来源:互联网 发布:快手特效视频软件 编辑:程序博客网 时间:2024/06/06 14:17

The Schengen Agreement was signed by a number of countries to uniform many visa-related questions and to allow tourists from outside of the Schengen area to enter and freely travel within Schengen member states using only one visa. A multiple-entry visa owner can perform many travels to any Schengen member state using a single visa, but migration laws limit the number of days he is allowed to stay there. Forany consecutive 180 days a visa owner is only allowed to be inside the Schengen area for no more than90 days in total.

A tourist has got his 5-year Schengen multiple-entry visa on October 18th 2010, therefore he could travel to and from the Schengen area at any of5·365 + 1 (2012 was a leap year)  = 1826 days.

Yesterday (October 17th, 2015) was the last day his visa was valid, and the tourist wants to know whether he has broken the migration laws and may face problems with obtaining a new Schengen visa. You are given the information about all trips to the Schengen member states he did using this visa and are to verify the rule about consecutive days for multiple-entry visa holders. According to the Schengen visa rules the day of arrival and the day of departure are considered to be days spent inside the Schengen area.


Input

The first line of the input contains only number of trips n (1 ≤ n ≤ 1826).

The i-th of the following n lines describes the i-th trip with two integersai anddi — the day of arrival to Schengen area and the day of departure respectively (1 ≤ ai ≤ di ≤ 1826). Days are numbered starting from the day the visa was issued.

It is guaranteed that these trips do not overlap, that is, each of 1826 days is a part of no more than one trip. Trips are given in arbitrary order.

Output

Output "Yes" (without quotes) if the tourist has followed the rules and may not worry about a new visa. Print "No" (without quotes) if he needs to start to look for an explanation to give to migration officer.

Example
Input
12 91
Output
Yes
Input
11 91
Output
No
Input
23 91180 200
Output
No
Input
2181 2701 90
Output
Yes
Note

In the second sample the tourist was in Schengen area for 91 days in the 180-day window which starts on day 1.

In the third sample the tourist was in Schengen area for 91 days in the 180-day window which started on day 2 (89 days from day 3 to day 91 and 2 days from day 180 to day 181).


题意就是说这个人从1到1826天内可以进入这个国家,但是在连续的180天内,不能待超过90天,给出,他来的时间和离开的时间,看是否符合条件

思路:开一个数组s[]如果第i天在这个国家是s[i]标记为1否则记为0,然后就跑连续的180天看是s[i]到s[i+180]的和是否大于90就行了;

可以先将最开始180天的和跑出来,剩下的每次减去第一天的然后加上第181天的在o(n)的时间内就能全部跑完。

#include <iostream>#include <cstdio>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <stack>#include <map>#define inf 0x3f3f3f3fusing namespace std;int s[2000];int main(){ios::sync_with_stdio(false);int n, l, r, i, j, sum, flag;while(cin>>n){memset(s,0,sizeof(s));sum = 0;while(n--){cin>>l>>r;for(i = l;i <= r;i++)s[i] = 1;}for(i = 1;i <= 180;i++){sum += s[i];}flag = 1;if(sum > 90){flag = 0;}if(flag){for(i = 1,j = 181;j <= 1826;i++,j++){sum = sum - s[i] + s[j];if(sum > 90){flag = 0;break;}}}if(flag)cout<<"Yes"<<endl;elsecout<<"No"<<endl;}    return 0;}


阅读全文
0 1