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
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxx = ;
struct Node{
int pos;
char dir;
}p[maxx];
bool cmp(Node a,Node b){
return a.pos<b.pos;
}
int main(){
int n;
scanf("%d",&n);
getchar();
for(int i=;i<n;i++){
scanf("%c",&p[i].dir);
}
for(int i=;i<n;i++){
scanf("%d",&p[i].pos);
} int ans=0x7fffffff;
for(int i=;i<n;i++){
if(p[i].dir!=p[i-].dir&&p[i].dir=='L'){
ans=min(ans,(p[i].pos-p[i-].pos)/);
}
}
if(ans<0x7fffffff){
printf("%d\n",ans);
}else{
printf("-1");
}
return ;
}

codeforces #363a Launch of Collider的更多相关文章

  1. 【模拟】Codeforces 699A Launch of Collider

    题目链接: http://codeforces.com/problemset/problem/699/A 题目大意: 给N个点,向左或向右运动,速度均为1,问最早什么时候有两个点相撞.无解输出-1 题 ...

  2. CodeForces 699A Launch of Collider

    枚举相邻两个$a[i]$与$a[i+1]$,如果$s[i]=R$并且$s[i+1]=L$,那么$i$和$i+1$会碰撞,更新答案. #pragma comment(linker, "/STA ...

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

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

  5. A. Launch of Collider (#363 Div.2)

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

  6. 【CodeForces 699A】Launch of Collider

    维护最新的R,遇到L时如果R出现过就更新答案. #include <cstdio> #include <algorithm> using namespace std; int ...

  7. Codeforces 363A Soroban

    模拟算盘 #include<bits/stdc++.h> using namespace std; int main() { char s[20]; scanf("%s" ...

  8. codeforces 363A

    #include<stdio.h>//这题挺有意思小学学的算盘 int main() { int n,i,m; while(scanf("%d",&n)!=EO ...

  9. CF699A Launch of Collider 题解

    Content 有 \(n\) 辆车在一条数轴上,第 \(i\) 辆车在 \(a_i\) 上,每辆车要么向左,要么向右.开始,它们以 \(1\) 个单位每秒的速度在行驶.问你第一次撞车发生在第几秒的时 ...

随机推荐

  1. [Markdown]纯文本标记语言MarkdowPad2--MD语法知识

    ##1.标题 代码 注:# 后面保持空格 # h1 ## h2 ### h3 #### h4 ##### h5 ###### h6 ####### h7 // 错误代码 ######## h8 // ...

  2. Problem O: 逆序输出——C语言初学者百题大战之二十

    #include<stdio.h> int main() { int a,b,c,d,e,n; scanf("%d",&n); a=n/; b=n%/; c=n ...

  3. Problem U: 零起点学算法19——输出特殊值

    #include<stdio.h> int main() { printf("%%d"); ; }

  4. Ajax 使用formdata 实现 无刷新表单上传

    FormData对象的作用就类似于这里的serialize()方法,不过FormData是浏览器原生的,且支持二进制文件 1.这里实现一个无刷新上传图片,成功后页面显示 点击button 触发隐藏的 ...

  5. 将Java程序打jar包并运行

    1)接着上篇博客继续说手动编译之后,将代码打成jar包,然后直接“java -jar lz.jar"运行不成功的问题.还是先上代码: 这个是Demo类: package org.lz.dem ...

  6. [读书笔记]iOS 7 UI设计 对比度

    好久没写随笔了,最近在读<iOS 7 byTutorials>,很不错,推荐给大家. 每一个好的程序员也都是一个设计师,不懂设计的程序员不是好的CTO.哈哈,开个小玩笑. iOS 7设计的 ...

  7. JavaSE目录

    常识,环境变量,注释 标示符,常量,进制转换,类型转换,位运算符,语句 数组,函数 面向对象 多线程 String 包装类 集合 其他对象 IO流,IO流--FileReader&&F ...

  8. INLINE-BLOCK和FLOAT(二)(转)

    一.一抹前言 没有爱的日子,时间如指尖细沙,不知不觉就流逝了.写“CSS float浮动的深入研究.详解及拓展(一)”和“CSS float浮动的深入研究.详解及拓展(二)”似乎就在不久前,然而相隔差 ...

  9. JavaScript的=、==和===

    (1) 百度知道上的解释: = 为对象赋值 == 表示两个对象toString值相等 === 表示两个对象类型相同且值相等 (2)  知乎上的解释: 绝大多数场合应该使用 === ,只有检测 null ...

  10. hive开窗函数over(partition by ......)用法

    一.over(partition by ......)主要和聚合函数sum().count().avg()等结合使用,实现分组聚合的功能 示列:根据day_id日期和mac_id机器码进行聚合分组求每 ...