B. Dasha and friends
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

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.

Input

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.

Output

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).

Examples
input
3 8
2 4 6
1 5 7
output
YES
input
4 9
2 3 5 8
0 1 3 6
output
YES
input
2 4
1 3
1 2
output
NO
Note

The first test is analyzed in the statement.

题意:给你一个环,然后让你安排A的起点和B的起点,使得某些特殊点到A的距离是a[i],某些点到B的距离是b[i],问你可不可行。

题解:暴力搜一遍

#include <iostream>
#include<cstdio>
using namespace std;
int n,l;
int a[],b[];
int main()
{
scanf("%d%d",&n,&l);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
bool flag;
for(int i=;i<=n;i++)
{
int start=(a[i]-b[]+l)%l;
flag=;
for(int j=;j<=n;j++)//假设A的起点为0坐标
{
if (a[(i+j-)%n+]!=(start+b[j])%l) {flag=;break;}
}
if (flag) break;
}
if (flag) printf("YES\n"); else printf("NO\n");
return ;
}

Codeforces Round #394 (Div. 2) B. Dasha and friends的更多相关文章

  1. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)

    E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle 构造

    E. Dasha and Puzzle 题目连接: http://codeforces.com/contest/761/problem/E Description Dasha decided to h ...

  3. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心

    D. Dasha and Very Difficult Problem 题目连接: http://codeforces.com/contest/761/problem/D Description Da ...

  4. Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力

    C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...

  5. Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力

    B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...

  6. Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题

    A. Dasha and Stairs 题目连接: http://codeforces.com/contest/761/problem/A Description On her way to prog ...

  7. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem —— 贪心

    题目链接:http://codeforces.com/contest/761/problem/D D. Dasha and Very Difficult Problem time limit per ...

  8. Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举

    题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seco ...

  9. Codeforces Round #394 (Div. 2) B. Dasha and friends —— 暴力 or 最小表示法

    题目链接:http://codeforces.com/contest/761/problem/B B. Dasha and friends time limit per test 2 seconds ...

  10. Codeforces Round #394 (Div. 2) C. Dasha and Password

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. hibernate自动建表之engine设置

    1.MYSQL的数据库引擎中,只有InnoDB和BDB(Berkley DB )包括了对事务处理和外键的支持.如果数据引擎建为MyISAM则rollback无效. 2.而hibernate自动建表的时 ...

  2. JQuery操作select中的option

    html页面代码例如以下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

  3. IOS JAVA PHP 安卓 通用加密方式

    PHP代码: class Aes { private $hex_iv = '00000000000000000000000000000000'; // converted JAVA byte code ...

  4. [DevOps] 认识一下

    大家都在说DevOps(Develop Operation),大概知道就是开发和运维沟通交流,一条线,然后使产品能够顺利的.短时间内上线.维稳什么的. 今天特意看了下 DockOne里面的一篇文章,再 ...

  5. 与进程相关的命令ps、kill

    一.概述 Ubuntu中主要有如下操作进程的命令 二.进程查看命令 ps 2.1 ps –l PPID:父进程的 PID PID:进程的PID S:进程状态,S:是指sleep睡眠状态:T:是挂起状态 ...

  6. 自动回复之实现随机回复与常用Mapper XML标签

    [常用Mapper XML标签] 1.基本的:select.insert.update 等 2.可读性.方便拼SQL:where.set.trim 3.减少重复:sql 4.逻辑控制:if.choos ...

  7. CSS 一个完整的例子

    My first web page What this is A simple page put together using HTML. I said a simple page put toget ...

  8. 理解 $nextTick 的作用

    有同学在看 Vue 官方文档时,对 API 文档中的 Vue.nextTick 和 vm.$nextTick 的作用不太理解. 其实如果看一下深入响应式原理 - vue.js中的有关内容,可能会有所理 ...

  9. linux驱动调试--修改系统时钟终端来定位僵死问题【转】

    本文转载自:http://blog.chinaunix.net/uid-20671208-id-4940381.html 原文地址:linux驱动调试--修改系统时钟终端来定位僵死问题 作者:枫露清愁 ...

  10. 选择使用Spring框架的原因(Spring框架为企业级开发带来的好处有哪些)