303954: CF761B. Dasha and friends

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

Description

Dasha and friends

题意翻译

# 题目描述 小A和小B参加障碍跑,跑道可能有多个,所有跑道是环形的,按逆时针方向跑,长度都是是L,都有n个障碍。 小A从起点A开始跑,沿途记录下经过的障碍物离开起点A的距离,如2,4,6;小B从起点B开始跑,沿途记录下经过的障碍物离开起点B的距离,如1,5,7。距离均为整数。 现在请你判断,小A和小B的使用的是否是同一个跑道。 ## 输入格式 第一行,两个整数n和L (1 ≤ n ≤ 50, n ≤ L ≤ 100),分别表示障碍物的数量和跑道的长度。 第二行,n个升序的整数,表示小A记录的障碍物离起点的距离,范围为0到L-1。 第三行,n个升序的整数,表示小B记录的障碍物离起点的距离,范围为0到L-1。 ## 输出格式 输出一个字符串,“YES”表示跑道相同,“NO”表示跑道不同。 ## 输入输出样例 ### 输入 #1 ``` 3 8 2 4 6 1 5 7 ``` ### 输出 #1 ``` YES ``` ### 输入 #2 ``` 4 9 2 3 5 8 0 1 3 6 ``` ### 输出 #2 ``` YES ``` ### 输入 #3 ``` 2 4 1 3 1 2 ``` ### 输出 #3 ``` NO ```

题目描述

Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation: The track is the circle with length $ L $ , in distinct points of which there are $ n $ barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track. Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the $ n $ barriers. Thus, each of them wrote $ n $ integers in the ascending order, each of them was between $ 0 $ and $ L-1 $ , inclusively. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF761B/2afd3f72f8cb58a425b7f260c67173d1e9095e01.png)Consider an example. Let $ L=8 $ , blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down the sequence $ [2,4,6] $ , and Sasha writes down $ [1,5,7] $ .There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks. Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ L $ ( $ 1<=n<=50 $ , $ n<=L<=100 $ ) — the number of barriers on a track and its length. The second line contains $ n $ distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from $ 0 $ to $ L-1 $ inclusively. The second line contains $ n $ distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from $ 0 $ to $ L-1 $ inclusively.

输出格式


Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes).

输入输出样例

输入样例 #1

3 8
2 4 6
1 5 7

输出样例 #1

YES

输入样例 #2

4 9
2 3 5 8
0 1 3 6

输出样例 #2

YES

输入样例 #3

2 4
1 3
1 2

输出样例 #3

NO

说明

The first test is analyzed in the statement.

Input

题意翻译

# 题目描述 小A和小B参加障碍跑,跑道可能有多个,所有跑道是环形的,按逆时针方向跑,长度都是是L,都有n个障碍。 小A从起点A开始跑,沿途记录下经过的障碍物离开起点A的距离,如2,4,6;小B从起点B开始跑,沿途记录下经过的障碍物离开起点B的距离,如1,5,7。距离均为整数。 现在请你判断,小A和小B的使用的是否是同一个跑道。 ## 输入格式 第一行,两个整数n和L (1 ≤ n ≤ 50, n ≤ L ≤ 100),分别表示障碍物的数量和跑道的长度。 第二行,n个升序的整数,表示小A记录的障碍物离起点的距离,范围为0到L-1。 第三行,n个升序的整数,表示小B记录的障碍物离起点的距离,范围为0到L-1。 ## 输出格式 输出一个字符串,“YES”表示跑道相同,“NO”表示跑道不同。 ## 输入输出样例 ### 输入 #1 ``` 3 8 2 4 6 1 5 7 ``` ### 输出 #1 ``` YES ``` ### 输入 #2 ``` 4 9 2 3 5 8 0 1 3 6 ``` ### 输出 #2 ``` YES ``` ### 输入 #3 ``` 2 4 1 3 1 2 ``` ### 输出 #3 ``` NO ```

加入题单

算法标签: