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.

题意:

对撞机的任意地方有带方向的粒子,求最短相遇时间。

注意:粒子位置是成递增排列的,故要想最短必是相邻且左边粒子方向为右,右边粒子方向为左。

附AC代码:

 #include<iostream>
#include<cstring>
using namespace std; const int INF=<<; int a[];
char b[];
int main(){
int n;
cin>>n;
cin>>b;
for(int i=;i<n;i++){
cin>>a[i];
}
int Min=INF;
for(int i=;i<n;i++){
if(Min>a[i]-a[i-]&&b[i]=='L'&&b[i-]=='R')
Min=a[i]-a[i-];
}
if(Min!=INF){
cout<<Min/<<endl;//对向相遇
}
else
cout<<"-1"<<endl;
return ;
}

最新文章

  1. 怎么写makefile?(转)
  2. Weblogic新增域(可以配置新端口)
  3. POJ 1064 Cable master (二分)
  4. 操作properties文件,注意抹掉最前面的&quot;file:&quot;
  5. hadoop与云技术、云计算混肴澄清
  6. [置顶] Objective-C ,ios,iphone开发基础:protocol 协议(委托,代理)的声明
  7. C#中hashtable的赋值、取值、遍历、排序操作
  8. 【转】listView中,checkBox的显示和隐藏
  9. 前端上传组件 - Plupload
  10. 前端编程提高之旅(六)----backbone实现todoMVC
  11. bonecp使用数据源
  12. hdu1013
  13. hdu_5776_sum(前缀和维护)
  14. JAVAEE学习——struts2_02:结果跳转方式、访问servletAPI方式、获得参数以及封装和练习:添加客户
  15. 利用反射操作bean的属性和方法
  16. 安卓开发笔记(十二):SQLite数据库储存(上)
  17. 本地部署JAVA SE环境
  18. LVS-DR模式 SOP
  19. 使用Charles对iPhone进行Http(s)请求拦截(抓包)
  20. Android Studio项目导入aar包报错

热门文章

  1. 调用Camera返回为空的分析及处理方法
  2. RFID 卡片防复制
  3. iOS UILabel文字缩进
  4. 第 3 章 第 1 题 精简冗余 if 语句问题 使用数组实现
  5. VLC For Android Ubuntu14.04编译环境搭建
  6. P1355 神秘大三角
  7. Struts2中的数据类型转换
  8. Android笔记之自定义PopupWindow
  9. Tomcat之catalina.out日志分割
  10. 数据结构之 线性表---单链表操作A (删除链表中的指定元素)