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 1and 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.

题意理解:有很多粒子在同一条直线上飞,速度是1,RL表示粒子的飞行方向,求粒子碰撞的最早时间,若不会碰撞就输出-1;

思路:只要是RL连着的就会碰撞,然后输出最小的minn/2;

 #include<bits/stdc++.h>
using namespace std;
int a[];
int main() {
int n;
string s;
cin>>n>>s;
for(int i=; i<n; i++)
cin>>a[i];
int minn=-;
for(int i=; i<n-; i++) {
if(s[i]=='R'&&s[i+]=='L') {
if(minn==-)
minn=a[i+]-a[i];
else
minn=min(minn,a[i+]-a[i]);
}
}
if(minn!=-)
cout<<minn/<<endl;
else
cout<<minn<<endl;
return ;
}

Codeforces Round #363 (Div. 2)->A. Launch of Collider的更多相关文章

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

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

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

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

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

  4. Codeforces Round #363 (Div. 2)

    A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...

  5. Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环

    题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...

  6. Codeforces Round #363 (Div. 2) A

     Description There will be a launch of a new, powerful and unusual collider very soon, which located ...

  7. Codeforces Round #363 (Div. 2) A 水

    Description There will be a launch of a new, powerful and unusual collider very soon, which located ...

  8. Codeforces Round #363 (Div. 2) D. Fix a Tree —— 并查集

    题目链接:http://codeforces.com/contest/699/problem/D D. Fix a Tree time limit per test 2 seconds memory ...

  9. Codeforces Round #363 (Div. 2) B. One Bomb —— 技巧

    题目链接:http://codeforces.com/contest/699/problem/B 题解: 首先统计每行每列出现'*'的次数,以及'*'出现的总次数,得到r[n]和c[m]数组,以及su ...

随机推荐

  1. 15个web前端的美轮美奂的 jQuery 图片特效

    jQuery是一个非常优秀的 JavaScript 框架,使用简单灵活,同时还有许多成熟的插件可供选择.其中,jQuery 最令人印象深刻的应用之一就是对图片的处理,它可以让帮助你在你的项目中加入各种 ...

  2. 济南学习 Day 4 T1 am

    完美的序列(sequence)Time Limit:1000ms Memory Limit:64MB题目描述LYK 认为一个完美的序列要满足这样的条件:对于任意两个位置上的数都不相同.然而并不是所有的 ...

  3. 济南学习 Day 3 T1 pm

    巧克力棒(chocolate)Time Limit:1000ms Memory Limit:64MB题目描述LYK 找到了一根巧克力棒,但是这根巧克力棒太长了,LYK 无法一口吞进去.具体地,这根巧克 ...

  4. 已有数据表的Mysql字符编码修改

    Mysql字符集修改应该如何实现呢?下面就为您详细介绍已用数据表的Mysql字符集修改方法,希望对您学习Mysql字符集方面能有所启迪. 环境:在应用开始阶段没有正确的设置字符集,在运行一段时间以后才 ...

  5. exynos 4412 eMMC配置及使用方法

    /** ****************************************************************************** * @author    Maox ...

  6. 打造简单实用的Thinkphp分页样式(Bootstrap版本)

    先吐槽一下ThinkPHP3.1版的分页样式,虽然看起来也很简单大方,但是所有的页码全是使用简单的数字,之间的空隙比较小,不大容易点,还有那个“前5页”和“后5页”显得有点多余,因为点击当前显示第一页 ...

  7. $.each遍历json对象

    查看一个简单的jQuery的例子来遍历一个JavaScript数组对象. var json = [ {"id":"1","tagName": ...

  8. php中session_start()相关问题分析与解决办法

    介绍下,在php中使用session时遇到的一些问题,与相关解决方法.1.错误提示Warning: Cannot send session cookie - headers already sentW ...

  9. MySQL语法语句大全

    一.SQL速成   结构查询语言(SQL)是用于查询关系数据库的标准语言,它包括若干关键字和一致的语法,便于数据库元件(如表.索引.字段等)的建立和操纵.   以下是一些重要的SQL快速参考,有关SQ ...

  10. python 安装 setuptools Compression requires the (missing) zlib module 的解决方案

    背景: 虚拟机centos下安装python辅助工具 setuptools报错,错误信息大概如下: Traceback (most recent call last): File "setu ...