首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CodeForces】699A - Launch of Collider(思维)

【CodeForces】699A - Launch of Collider(思维)

作者头像
FishWang
发布2025-08-26 15:31:38
发布2025-08-26 15:31:38
7000
代码可运行
举报
运行总次数:0
代码可运行

点击打开题目

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

代码语言:javascript
代码运行次数:0
运行
复制
4
RLRL
2 4 6 10

output

代码语言:javascript
代码运行次数:0
运行
复制
1

input

代码语言:javascript
代码运行次数:0
运行
复制
3
LLR
40 50 60

output

代码语言:javascript
代码运行次数:0
运行
复制
-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.

左边的往右走右边的往左走,这样才能相遇而且是该段最近的一次相遇。

扫过去更新ans就行了。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	char a[200000+11];
	int num[200000+11];		//1往右走,-1往左走 
	while (~scanf ("%d",&n))
	{
		memset (num,0,sizeof (num));
		scanf ("%s",a+1);
		for (int i = 1 ; i <= n ; i++)
			scanf ("%d",&num[i]);
		int ans = 1e9;
		int flag = false;
		for (int i = 1 ; i < n ; i++)
		{
			if (a[i] == 'R' && a[i+1] == 'L')
			{
				flag = true;
				ans = min (ans , (num[i+1] - num[i]) >> 1);
			}
		}
		if (flag)
			printf ("%d\n",ans);
		else
			printf ("-1\n");
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档