# Launch of Collider

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.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
using namespace std;

int n;
char s[200010];
int num[200010];

int main()
{
//freopen("in.txt", "r", stdin);
while (cin >> n)
{
cin >> s;
int ans = INT_MAX;
cin >> num[0];
for (int i = 1; i < n; i++)
{
cin >> num[i];
if (s[i - 1] == 'R'&&s[i] == 'L')
{
ans = min(ans, num[i] - num[i - 1]);
}
}
if (ans < INT_MAX)
cout << ans/2 << endl;
else
cout << "-1" << endl;
}
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：Launch of Collider 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)