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 ;
}

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

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

  2. A. Launch of Collider Codeforces Round #363 (Div2)

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

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

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

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

  5. codeforces #363a Launch of Collider

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

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

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

  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) A 水

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

  9. Codeforces Round #363 (Div. 2)

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

随机推荐

  1. Audio原理图设计

    1.DMIC 1)当双MIC时,通过MIC上的Selection PIN脚PULL  U/D进行左右channel选择.

  2. 车牌识别--OMAP4430处理器上測试

    OMAP4430(ME865) arm-linux-gcc 4.5.1(FriendlyARM) 软浮点执行结果: root@lj:/workspace/carid# arm-linux-gcc ca ...

  3. kubernetes之创建基于名称空间的内存和cpu限额示例

    系列目录 首先我们创建一个名称空间 kubectl create namespace quota-mem-cpu-example 创建资源配额 apiVersion: v1 kind: Resourc ...

  4. iOS8 PUSH解决方法

    本文转载至 http://blog.csdn.net/pjk1129/article/details/39548523     - (void)registerForRemoteNotificatio ...

  5. jquery插件pagination实现分页

    1.效果 2.HTML代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind=" ...

  6. dataware fact 事实 不可更新 data warehousing business intelligence 优劣判据

    不可 Kimball维度建模 维度建模,而非数据建模 文本型度量是对某些事情的描述.虽然以文本方式度量事实是可行的,但是应将其放入维度表中,除非对事实表的每个行,其文本是唯一的. 数据仓库的好坏直接取 ...

  7. Jsp中操作页面显示

    通常我们想改变网页中的显示可以用下面的方式. <script type="text/javascript">function show(){     document. ...

  8. Android笔记之为自定义对话框添加移动动画效果

    给底部的对话框添加移动动画效果 可通过Window.setWindowAnimations(int resId)设置 SharingDialog.java package com.bu_ish.sha ...

  9. Java中实现函数的阻塞

    使用Object.wait()即可实现阻塞,使用Object.notify()解除阻塞,代码示例如下 MainFrame.java import javax.swing.JFrame; import ...

  10. 数据库的update、delete、insert和select用法

    String sql=null; 1.sql="update 表名 set <列名>=<表达式> [where=<表达式>]" 2.sql=&q ...