303892: CF750B. New Year and North Pole

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

New Year and North Pole

题意翻译

在这个问题中,我们假设地球是一个完全圆的球,它的表面是一个完美的球体。赤道和任何子午线的长度正好为 40000 公里。因此,从北极到南极或从南极到北极的旅行需要 20000 公里。 Limak,住在北极。临近新年,他帮助一些人在世界各地运送包裹。Limak 得到了一个描述,假设他是从北极开始的,他应该如何移动。描述由 n 部分组成。在他的旅程的第 i 部分,利马克应该朝着一个方向移动 ti 公里,这个字符串是“North”,“South”,“West”,“East”之一。 Limak不确定描述是否有效。你必须帮助他检查以下情况: • 如果在任何时候(在任何指示之前或在执行其中一项指示时)Limak 在北极,他只能向南移动。 • 如果在任何时候(在任何指示之前或在执行其中一项指示时)Limak 在南极,他只能向北方移动。 • 旅程必须在北极结束。 检查是否满足上述条件,并输出“YES”或“NO”。

题目描述

In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly $ 40000 $ kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly $ 20000 $ kilometers. Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of $ n $ parts. In the $ i $ -th part of his journey, Limak should move $ t_{i} $ kilometers in the direction represented by a string $ dir_{i} $ that is one of: "North", "South", "West", "East". Limak isn’t sure whether the description is valid. You must help him to check the following conditions: - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. - If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. - The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line.

输入输出格式

输入格式


The first line of the input contains a single integer $ n $ ( $ 1<=n<=50 $ ). The $ i $ -th of next $ n $ lines contains an integer $ t_{i} $ and a string $ dir_{i} $ ( $ 1<=t_{i}<=10^{6} $ , ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF750B/bad8e6778e4440b96077dcc3eab91b8cb46271e1.png)) — the length and the direction of the $ i $ -th part of the journey, according to the description Limak got.

输出格式


Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.

输入输出样例

输入样例 #1

5
7500 South
10000 East
3500 North
4444 West
4000 North

输出样例 #1

YES

输入样例 #2

2
15000 South
4000 East

输出样例 #2

NO

输入样例 #3

5
20000 South
1000 North
1000000 West
9000 North
10000 North

输出样例 #3

YES

输入样例 #4

3
20000 South
10 East
20000 North

输出样例 #4

NO

输入样例 #5

2
1000 North
1000 South

输出样例 #5

NO

输入样例 #6

4
50 South
50 North
15000 South
15000 North

输出样例 #6

YES

说明

Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF750B/9bb594fe352848bbba36035935a49c02ad65109a.png)

Input

题意翻译

在这个问题中,我们假设地球是一个完全圆的球,它的表面是一个完美的球体。赤道和任何子午线的长度正好为 40000 公里。因此,从北极到南极或从南极到北极的旅行需要 20000 公里。 Limak,住在北极。临近新年,他帮助一些人在世界各地运送包裹。Limak 得到了一个描述,假设他是从北极开始的,他应该如何移动。描述由 n 部分组成。在他的旅程的第 i 部分,利马克应该朝着一个方向移动 ti 公里,这个字符串是“North”,“South”,“West”,“East”之一。 Limak不确定描述是否有效。你必须帮助他检查以下情况: • 如果在任何时候(在任何指示之前或在执行其中一项指示时)Limak 在北极,他只能向南移动。 • 如果在任何时候(在任何指示之前或在执行其中一项指示时)Limak 在南极,他只能向北方移动。 • 旅程必须在北极结束。 检查是否满足上述条件,并输出“YES”或“NO”。

加入题单

算法标签: