CF #403 Div.2 A

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 from1 ton. 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 thei-th sock Andryusha took out was from pairxi.

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 pair1 and put it on the table.
  • Socks (1, 2) were on the table. Andryusha took out a sock from pair1, and put this pair into the wardrobe.
  • Sock (2) was on the table. Andryusha took out a sock from pair3 and put it on the table.
  • Socks (2, 3) were on the table. Andryusha took out a sock from pair2, and put this pair into the wardrobe.
  • Sock (3) was on the table. Andryusha took out a sock from pair3 and put this pair into the wardrobe.
Thus, at most two socks were on the table at the same time.
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#define LL long long 
#define MAX 200010
using namespace std;

int a[MAX];
int main()
{
	
	int n;
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
		a[i]=2;
	int tab=0;
	int ans=0;
	for(int i=1;i<=2*n;i++)
	{
		int c;
		scanf("%d",&c);
		a[c]-=1;
		if(a[c]==1)
		{
			tab++;
			ans=max(ans,tab);
		}
		else
		{
			tab--;
		}
	} 
	printf("%d\n",ans);
	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="com.test.bean.Goods,java.util.ArrayList" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>购物车</title> <style type="text/css"> table{border-collapse:collapse;} td{border:1px solid black; text-align:center; } #deal{margin-left:200px} </style> </head> <body> <jsp:useBean id="cart" class="com.test.bean.Cart" scope="session"></jsp:useBean> <%if(cart==null||cart.getGoodslist().size()==0) out.println("购物车空空如也.....<a href=&#39;index.jsp&#39;>返回商品首页</a>"); else{ ArrayList<Goods>goodslist=cart.getGoodslist(); %> <div> 当前购物车共有<%=cart.getGcount() %>件物品    <a href=&#39;index.jsp&#39;>返回商品首页</a><br> <table><tr> <td>序号</td> <td>商品号</td> <td>商品名称</td> <td>价格</td> <td>数量</td> <td>小计</td> <td>描述</td></tr> <%for(int i=0;i<goodslist.size();i++){ Goods goods=goodslist.get(i); %> <tr> <td><%=i+1 %></td> <td><%=goods.getGid() %></td> <td><%=goods.getGname() %></td> <td><%= String.format("%.2f", goods.getGprice())%></td> <td><%=goods.getGcount() %></td> <td><%=String.format("%.2f", goods.getGprice()*goods.getGcount()) %></td> <td><a href="<%=request.getContextPath() %>/Servlet/DelCartServlet?gid=<%=goods.getGid() %>">删除</a></td></tr> <%}%> </table><br> <span>总计</span><%=String.format("%.2f",cart.getTotal())%>    <input type="button" id="deal" value="购买" /></input> </div> <%}%> <script type="text/javascript"> var dealbutton=document.getElementById("deal"); dealbutton.onclick=function(){ var cf=confirm("确定购买吗?"); if(cf==true){ window.location.href="Servlet/DealServlet"; } } </script> </body> </html> 修改删除功能,在购物车物品数量大于1的情况下点击“删除”时减少1个,等于1时删除此项商品;
06-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值