您的位置:首页 > 其它

【Codeforces Round 363 (Div 2) A】【水题】Launch of Collider 机器人最早碰撞时间

2016-07-26 09:06 330 查看
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.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1#define rs o<<1|1typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 2e5 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n;
char s
;
int a
;
int main()
{
while (~scanf("%d", &n))
{
scanf("%s", s + 1);
for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
int ans = 1e9;
for (int i = 1; i < n; ++i)if (s[i] == 'R' && s[i + 1] == 'L')
{
gmin(ans, a[i + 1] - a[i] >> 1);
}
if (ans == 1e9)ans = -1;
printf("%d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息