CodeForces 699A Launch of Collider

题目链接:http://codeforces.com/problemset/problem/699/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 <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
string str;
int num[maxn];
int n;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> str;
	for (int i=0; i<n; ++i)
		cin >> num[i];
	int ans = INT_MAX;
	for (int i=1; i<str.size(); ++i)
		if (str[i-1]=='R' && str[i]=='L')
			ans = min(ans, (num[i]-num[i-1])/2);
	cout << (ans==INT_MAX ? -1 : ans) << endl;
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值