Codeforces 782 Andryusha and Socks
来源:互联网 发布:js代码混淆 编辑:程序博客网 时间:2024/05/19 14:20
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.
11 1
1
32 1 1 3 2 3
2
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.
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 100050;int a[maxn];int main(){int n;while((scanf("%d",&n))!=EOF){int mx=0;int ans=0;memset(a,0,sizeof(a));for(int i=1;i<=2*n;i++){ int b;scanf("%d",&b);a[b]++;if(a[b]==2) mx--;else mx++;ans=max(ans,mx);}printf("%d\n",ans);}return 0;}
- Codeforces 782 Andryusha and Socks
- 【codeforces 782A】Andryusha and Socks
- codeforces 782a Andryusha and Socks
- Codeforces 780A-Andryusha and Socks
- CodeForces 780A Andryusha and Socks【水题】
- cf 782A Andryusha and Socks
- cf 782A Andryusha and Socks
- A. Andryusha and Socks
- Andryusha and Socks
- 【codeforces 782C】Andryusha and Colored Balloons
- codeforces 782c Andryusha and Colored Balloons
- Codeforces Round #403 (Div. 2) A. Andryusha and Socks(简单模拟)
- Codeforces Andryusha and Colored Balloons
- Codeforces 782C Andryusha and Colored Balloons dfs
- Codeforces 782C Andryusha and Colored Balloons(BFS)
- codeforces 782C Andryusha and Colored Balloons【构造】
- 【codeforce】403 Div.2 A Andryusha and Socks
- CF-Round#403 Div2 A. Andryusha and Socks
- 指令与数据的区分
- 448. Find All Numbers Disappeared in an Array
- 同页面打开浮层窗口并加载来自action的信息
- CCF 相邻数对
- 微服务的前世今生
- Codeforces 782 Andryusha and Socks
- 浅析this指针
- hibernate的一级缓存和二级缓存机制
- R
- VS 2010 显示行号,调整字体
- c++之虚函数与多态
- 八大排序 C++
- jni返回byte[]
- python中PIL的安装——转自脚本之家