Launch of Collider

来源:互联网 发布:最好的erp软件 编辑:程序博客网 时间:2024/05/21 03:54

Description

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.

Sample Input

Input
4RLRL2 4 6 10
Output
1
Input
3LLR40 50 60
Output
-1

Hint

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.


#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<vector>#include<string>#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>using namespace std;struct point{int x;int aim;}a[200000+10];char des[200000+10];int main(){int n;int i;int min=0x3f3f3f3f;scanf("%d",&n);scanf("%s",&des);for(i=0;i<n;i++){if(des[i]=='L')a[i+1].aim=0;if(des[i]=='R')a[i+1].aim=1;}for(i=1;i<=n;i++){scanf("%d",&a[i].x);}for(i=1;i<n;i++){if(a[i].aim&&!a[i+1].aim){int s=(a[i+1].x-a[i].x)/2;if(s<min)min=s;}}if(min!=0x3f3f3f3f)printf("%d\n",min);elseprintf("-1\n");return 0;}


1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 线刷也不成功该怎么办 红米2开不了机怎么办 魅族无限重启怎么办 坚果pro无法双清怎么办 usb外置网卡网速慢怎么办? 无线路由器被改密码怎么办 电脑打不开flv格式的视频怎么办 电脑打不开pdf格式的文件怎么办 pdf格式在电脑上打不开怎么办 zip压缩的时候空间不足怎么办 电子发票填抬头错了怎么办 发票写错一个字怎么办 普票税率开错了怎么办 税率开错为17了怎么办 电子发票抬头错了怎么办 发票抬头错了一个字怎么办 5月税率开错了怎么办 如果发票是假的怎么办 发票收款人名字写错了怎么办 医院发票名字写错了怎么办 购买方发票联丢失怎么办 市中区超市办理发票怎么办 发票购买薄丢了怎么办 发票领用簿丢了怎么办 摩托车证扣12分怎么办 初中孩孑想扩展单词量怎么办 恒安保险倒闭了怎么办 小麦收割机卸粮筒总是转怎么办 非牛顿体结块了怎么办 非牛顿流体硬了怎么办 玩具枪子弹打到眼睛怎么办 杭州磨床7130噪音大怎么办 步兵太苦还有一年怎么办 检法事业编怎么办最新 河北省事业单位改企编制怎么办 梦飞去虎牙锐雯怎么办 蚂蚁借呗还款钱没到账怎么办 蚂蚁借呗没有按时还款怎么办 新装的win7没有网卡驱动怎么办 3d电影没眼睛怎么办 看vr手机发烫变卡怎么办