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. Cocos2d-x多场景切换生命周期

    在多个场景切换时候,场景的生命周期会更加复杂.这一节我们介绍一下场景切换生命周期. 多个场景切换时候分为几种情况: 情况1,使用pushScene函数从实现HelloWorld场景进入Setting场 ...

  2. c++对象内存布局

    这篇文章我要简单地讲解下c++对象的内存布局,虽然已经有很多很好的文章,不过通过实现发现有些地方不同的编译器还是会有差别的,希望和大家交流. 在没有用到虚函数的时候,C++的对象内存布局和c语言的st ...

  3. linux系统环境变量.bash_profile/bashrc文件

    系统环境变量的查看: [root@localhost ~]# envHOSTNAME=localhost.localdomainSELINUX_ROLE_REQUESTED=TERM=xtermSHE ...

  4. 清空系统日志shell scripts——自学笔记

    这是一个清空系统日志的脚本: vim logmess_clean.sh #bin/bash        //该脚本所使用的shell解释器 cd /var/log/  //切换到存放日志目录 ech ...

  5. VHDL基本常识

    std_logic_vector和integer需要通过signed或unsigned进行间接转换(强制转换) a_std <= std_logic_vector(to_unsigned(a_i ...

  6. ASP.Net网站部署失败

    部署站点时候,出现如下错误 “/”应用程序中的服务器错误. ---------------------------------------------------------------------- ...

  7. 值类型的Constructor

    使用C#的时候我们最熟悉的是类,也就是Reference Type,翻译成中文是引用类型.但是C#还有另外的一种类型往往被我们用的最多缺经常被忽视,这种类型就是值类型(Value Type). 值类型 ...

  8. linux lsof命令的使用

    lsof(list open files)是一个列出当前系统打开文件的工具.在UNIX环境下,任何事物都是以文件的形式存在的,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件. 像传输协议(T ...

  9. perl编程中的map函数示例

    转自:http://www.jbxue.com/article/14854.html 发布:脚本学堂/Perl  编辑:JB01   2013-12-20 10:20:01  [大 中 小] 本文介绍 ...

  10. XAML 概述三

    通过对前面2节对XAML的介绍,我们对XAML有了一定的认识.这一节我们来简单了解一下部分XAML命名空间(x:)语言功能. x命名空间映射的是http://schemas.microsoft.com ...