题目描述:
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?
输入描述:
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.
输出描述:
Print single integer — the maximum number of socks that were on the table at the same time.
输入:
1
1 1
3
2 1 1 3 2 3
输出:
1
2
题意:
有N双袜子,第i双袜子的每只袜子编号为i。现在知道从袋子中拿取袜子的顺序,袜子一只一只拿。如果桌子上有配对的袜子,就将这双袜子放进柜子里;如果没有,就将袜子放在桌子上。问桌子上最多存在几只袜子
题解:
直接搞
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100090],n;
int main(){
while(scanf("%d",&n)!=EOF){
int k,sum = 0,ans = 0;
memset(a,0,sizeof a);
for(int i = 1;i <= 2 * n;i ++){
scanf("%d",&k);
if(a[k]){
a[k] --;
sum --;
}
else{
sum ++;
ans = max(sum,ans);
a[k] ++;
}
}
printf("%d\n",ans);
}
return 0;
}