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. ebay的api的开发技术笔记

    使用eBay API基本步骤介绍 要开始使用eBay API,需要如下基本步骤: 1.    注册开发帐号: https://developer.ebay.com/join/Default.aspx ...

  2. 20141212--C#对象比较

    static void Main(string[] args) { Class2 oo = new Class2(); oo.shu = ; oo.zi = "你"; Class2 ...

  3. OC10_代理反向传值

    // // ProtectedDelegate.h // OC10_代理反向传值 // // Created by zhangxueming on 15/6/24. // Copyright (c) ...

  4. 炫酷实用的jQuery插件 涵盖菜单、按钮、图片

    新的一周开始了,今天我们要为大家分享一些全新的jQuery插件和HTML5/CSS3应用,这些jQuery插件不仅非常炫酷,而且还挺实用,这次的分享包含jQuery菜单.CSS3按钮已经多种图片特效, ...

  5. Cllimbing Stairs [LeetCode 70]

    1- 问题描述 You are climbing a stair case. It takes n steps to reach to the top. Each time you can eithe ...

  6. 运行maven报错:经过检查是因为maven不兼容jdk1.6,重新安装1.7解决

    cmd mvn -v报错: Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apach ...

  7. 【风马一族_Android】Android 前端内容

    Android 前端内容 4.1 View 类概述 4.1.1 关于 View //类型说明 view(视图)指的是用户界面组件的基本构建基块.一个视图占据屏幕上的矩形区域,负责绘图和事件处理.视图是 ...

  8. UBUNTU12.4 安装磊科无线网卡驱动

    UBUNTU12.4 安装磊科无线网卡驱动 在淘宝低价买了一个网卡,回来发现不能用 ,擦 无语了. 无赖只能在网上各种找驱动,编译 安装 .今天在终于安装好了WIFI驱动了: 下载地址:https:/ ...

  9. ADO.NET笔记——使用通用数据访问

    相关知识: 前面所有示例,君是访问特定的数据库(SQL Server),因此注入SqlConnection.SqlCommand.SqlDataReader.SqlDataAdapter等类名都添加了 ...

  10. Flex-box 学习

    .flex-cont{ /*定义为flexbox的“父元素”*/ display: -webkit-box; display: -webkit-flex; display: flex; /*子元素沿主 ...