A. Launch of Collider

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.

You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.

Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.

Input

The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles.

The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.

The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.

Output

In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.

Print the only integer -1, if the collision of particles doesn't happen.

Examples

Input

4 RLRL 2 4 6 10

Output

1

Input

3 LLR 40 50 60

Output

-1

Note

In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.

In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.

___________________

题意:

第一行表示有n个粒子,第二行表示他们分别向R(ight)或L(eft)方向移动,第三个是他们从哪个点开始移动。问当第一个粒子相撞的时候时间是多少?

——————————————————————

这道题我蠢了,一开始写了个O(n^2)级别的代码,枚举了每两个数的各种可能取最小值。以为数据20W*20W是4e9左右,实际上是4e10……要是4e10根本不会去试O(n^2)了……当时大概知道O(n^2)应该过不了,但是想着A题应该不会用高级算法吧(我甚至想到了线段树之类的) , 然后想着优化一下或许能过。

附O(n^2)自带超级大常数代码(后来还试了几下是不是cin cout 效率低换了 scanf printf ):

这道题最蠢在英语上……后来去查了下题解,发现别人写的if ( a[j] == 'R' && a[j+1] == 'L' ) 这样的代码才意识到我遗漏了什么。

回去重新读题发现坐标是按升序排列,也就是说只要找相邻的RL区间最小就是答案。

被自己气哭了……

附AC代码:

#include<cstdio>
struct
{
char a ;
int b;
} x[200010]; int main()
{
int n ;
scanf("%d",&n);
getchar(); // 吞掉键盘缓冲区的换行符
//(这里曾以为CF是LINUX,所以用了两个getchar(),wrong了才改的)
for( int i = 0 ; i < n ; i++ )
scanf("%c",&x[i].a);
getchar();
int min = 1e9 + 1 ;
int flag = 1 ;
for( int i = 0 ; i < n ; i++)
scanf("%d",&x[i].b);
for( int j = 0 ; j < n ; j++)
if( x[j+1].a == 'L' && x[j].a == 'R' && x[j].b < x[j+1].b )
{
if ( x[j+1].b - x[j].b < min) min = x[j+1].b - x[j].b ;
flag = 0;
}
if( flag == 0 )cout << (min >> 1) << endl ;
else cout << "-1" << endl ;
return 0;
}

A. Launch of Collider Codeforces Round #363 (Div2)的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  4. Codeforces Round 363 Div. 1 (A,B,C,D,E,F)

    Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...

  5. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  6. Codeforces Round #363 (Div. 2)->A. Launch of Collider

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #363 Div.2[111110]

    好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...

  8. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  9. Codeforces Round #363 (Div. 2) A、B、C

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. python的web开发环境Django配置

    我的系统的windows10: 第一步,安装python3.5 第二步,配置django,如图所示,在python的安装目录下的Scripts里面执行:pip install Django,我这儿提示 ...

  2. WPF之DatePicker使其只能选择日期,不能输入日期

    <DatePicker.Resources>  <Style TargetType="DatePickerTextBox">           <S ...

  3. C# 委托的三种调用示例(同步调用 异步调用 异步回调)

    首先,通过代码定义一个委托和下面三个示例将要调用的方法: 复制代码 代码如下: public delegate int AddHandler(int a,int b);    public class ...

  4. 使用SQL Server视图的优缺点

    SQL Server视图我们经常会用的到,下面就为您介绍使用SQL Server视图的优缺点,希望可以对您SQL Server视图有更多的了解. 在程序设计的时候必须先了解视图的优缺点,这样可以扬长避 ...

  5. NSLineBreakMode

    typedef enum {    UILineBreakModeWordWrap = 0,    UILineBreakModeCharacterWrap,    UILineBreakModeCl ...

  6. 使用mybatis多表联查的时候结果异常及springmvc的理解

    今天使用mybatis多表联查的时候,在dos窗口查询时可以出结果集,但是使用mybatis查询的时候最后返回的结果只有最后一个结果 然后研究了半天没弄出来,后来无意中发现添加了最外层从表的ID字段后 ...

  7. jquery常用的选择器

    jquery用选择器来得到jquery对象,进而进行一些操作. 一.基本选择器 1.id选择器.示例:选择id为one的元素 var $one = $("#one"); 2.类选择 ...

  8. Android5.1源码Xposed框架编译

    介绍 Xposed框架是一款可以在不修改APK的情况下影响程序运行(修改系统)的框架服务,基于它可以制作出许多功能强大的模块,且在功能不冲突的情况下同时运作 . 对于Android5.1系统,官方提供 ...

  9. MongoDB高级查询用法大全

    转载 http://blog.163.com/lgh_2002/blog/static/440175262012052116455/ 详见官方的手册: http://www.mongodb.org/d ...

  10. android app 集成 支付宝支付 微信支付

    项目中部分功能点需要用到支付功能,移动端主要集成支付宝支付和微信支付 支付宝sdk以及demo下载地址:https://doc.open.alipay.com/doc2/detail.htm?spm= ...