Codeforces Round #403 (Div. 2)A+B

来源:互联网 发布:40周胎儿发育标准数据 编辑:程序博客网 时间:2024/04/29 18:17

A. Andryusha and Socks

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

Andryusha is an orderly boy and likes to keep things in their place.

Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.

Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?

Input

The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs.

The second line contains 2n integers x1, x2, …, x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi.

It is guaranteed that Andryusha took exactly two socks of each pair.

Output

Print single integer — the maximum number of socks that were on the table at the same time.

Examples

Input
1
1 1

Output
1

Input
3
2 1 1 3 2 3

Output
2

Note

In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.

In the second example Andryusha behaved as follows:
• Initially the table was empty, he took out a sock from pair 2 and put it on the table.
• Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table.
• Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe.
• Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table.
• Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe.
• Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
Thus, at most two socks were on the table at the same time.
题意:你有n双袜子,每次拿出一只放在桌子上,如果有颜色相同的,就放起来。问桌子上最多同时存在多少只袜子。
题解:简单判断一下就好。
代码:

#include <bits/stdc++.h>#define ll long longusing namespace std;int n,x;int a[1001000];map<int,int>mp;int main(){    cin>>n;    int cnt,ans;    cnt=ans=0;    for(int i=1;i<=2*n;i++)    {        cin>>x;        if(mp[x]==0)        {            cnt++;            mp[x]++;        }        else        {            ans=max(ans,cnt);            cnt--;            mp[x]--;        }    }    cout<<ans<<endl;}

B. The Meeting Place Cannot Be Changed

time limit per test:5 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.

At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north.

You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn’t need to have integer coordinate.

Input

The first line contains single integer n (2 ≤ n ≤ 60 000) — the number of friends.

The second line contains n integers x1, x2, …, xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters.

The third line contains n integers v1, v2, …, vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters per second.

Output

Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road.

Your answer will be considered correct, if its absolute or relative error isn’t greater than 10 - 6. Formally, let your answer be a, while jury’s answer be b. Your answer will be considered correct if holds.

Examples

Input
3
7 1 3
1 2 1

Output
2.000000000000

Input
4
5 10 3 2
2 3 2 4

Output
1.400000000000

Note

In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
题意:给出n个人的位置和速度,求最短时间使他们积聚到一个点。题解:二分时间,当出现max(l)>min(r)时,为不可能。
代码:

#include <bits/stdc++.h>#define ll long long#define eps 1e-6using namespace std;const int N=600010;struct node{    double pos,v;    bool operator < (const node &t)const    {        return pos<t.pos;    }} a[N];double l[N];double r[N];double minn[N];double maxn[N];int n,cnt;int Slove(double mid){    for(int i=0; i<n; i++)    {        l[i]=a[i].pos-mid*a[i].v;        r[i]=a[i].pos+mid*a[i].v;    }    double posl=l[0];    double posr=r[0];    for(int i=1; i<n; i++)    {        posl=max(posl,l[i]);        posr=min(posr,r[i]);        if(posl>posr)return 0;    }    return 1;}int main(){    cin>>n;    for(int i=0; i<n; i++) cin>>a[i].pos;    for(int i=0; i<n; i++) cin>>a[i].v;    cnt=0;    sort(a,a+n);    double ans=-1;    double l=0;    double r=1000000005;    while(cnt<=150)    {        cnt++;        double mid=(l+r)/2;        if(Slove(mid))        {            r=mid;            ans=mid;        }        else l=mid;    }    printf("%.8lf\n",ans);}
0 0