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. sql优化--in和exists效率

    系统要求进行SQL优化,对效率比较低的SQL进行优化,使其运行效率更高,其中要求对SQL中的部分in/not in修改为exists/not exists 修改方法如下: in的SQL语句 SELEC ...

  2. sqlite增删改查

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  3. 8. Shell 文件包含

    1. 语法 . filename # 注意点号(.)和文件名中间有一空格 或 source filename ### test.sh #!/bin/bash url="www.baidu.c ...

  4. iOS 打包上传AppStore相关(2)-Xcode相应配置

    上一篇描述了如何在AppleDeveloper创建Certificates.App IDs和Provisioning Profiles的过程.本篇将详细描述在Xcode部分我们需要做的配置. 1.配置 ...

  5. 安装mysql的遇到的问题

    源:安装用的是mysql官网的binary包. 之前装mysql都是直接放到/usr/local,就想试试放到其他地方,然后..就悲剧了. 安装步骤没啥说的,官网上有.因为放置的位置不一样所以有些执行 ...

  6. ftp服务器端的安装及配置

    搭建过程 安装 vsftp 服务(yum 安装即可) 配置/etc/vsftpd/vsftpd.conf   anonymous_enable=NO #禁止匿名登录 local_enable=YES ...

  7. windows线程池四种情形(win核心读书笔记)

    windows线程池四种情形(win核心读书笔记) Mircosoft从Windows2000引入线程池API,并在Vista后对线程池重新构架,引入新的线程池API.以下所有线程池函数均适用于Vis ...

  8. javascript 局部变量和全局变量

    刚开始学js,遇到了一个奇怪的问题,查找之后知道了答案 需要记住两句话 1 Javascript的变量的scope是根据方法块来划分的(也就是说以function的一对大括号{ }来划分).切记,是f ...

  9. 变更mysql数据库文件目录 Linux

    本次需要将mysql默认的数据库文件路径/var/lib/mysql 改为新挂载的目录/data/mysql上,需要做以下修改 1.停止mysql服务 service mysqld stop 2.复制 ...

  10. underscore.js中的节流函数debounce及trottle

    函数节流   throttle and debounce的相关总结及想法 一开始函数节流的使用场景是:放止一个按钮多次点击多次触发一个功能函数,所以做了一个clearTimeout setTimeou ...