time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output

Problem Description

 Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.

Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from \(1\) to \(10^6\). Thus, the system logs events of two forms:

  • "\(+\ r_i\)" — the reader with registration number \(r_i\) entered the room;
  • "\(-\ r_i\)" — the reader with registration number l\(r_i\) left the room.

The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.

Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.

Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.

Input

  The first line contains a positive integer \(n (1 ≤ n ≤ 100)\) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as ""\(+\ r_i\) or "\(-\ r_i\)", where \(r_i\) is an integer from \(1\) to \(10^6\), the registration number of the visitor (that is, distinct visitors always have distinct registration numbers).

It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

Output

Print a single integer — the minimum possible capacity of the reading room.

Examples

input

6
+ 12001
- 12001
- 1
- 1200
+ 1
+ 7

output

3

input

2
- 1
- 2

output

2

input

2
+ 1
- 1

output

1

题意

给出\(n\)个进出图书馆的人的编号,问图书馆的容量最小可以是多少

思路

\(res\)和\(ans\)分别代表当前图书馆的人数和图书馆的容量

如果编号为\(a_i\)的人出去了,并且\(a_i\)没有在之前出现过,那么图书馆的容量增加\(1\),如果出现过,当前图书馆的人数减\(1\)

当进来人的时候,当前图书馆的人数增加\(1\),如果\(res>ans\),那么图书馆的容量也加\(1\)

代码

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e6+10;
const int mod=1e9+7;
const int maxm=1e3+10;
using namespace std;
struct wzy
{
string opt;
int id;
}p[maxn];
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("/home/wzy/in", "r", stdin);
freopen("/home/wzy/out", "w", stdout);
srand((unsigned int)time(NULL));
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
map<int,int>mp;
for(int i=1;i<=n;i++)
cin>>p[i].opt>>p[i].id;
// 图书馆的总容量
int ans=0;
// 当前图书馆的人数
int res=0;
for(int i=1;i<=n;i++)
{
if(p[i].opt=="-")
{
if(!mp[p[i].id])
ans++;
else
res--;
}
if(p[i].opt=="+")
{
res++;
if(res>ans)
ans++;
mp[p[i].id]=1;
}
}
cout<<ans<<endl;
#ifndef ONLINE_JUDGE
cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
#endif
return 0;
}

Codeforces 567B:Berland National Library(模拟)的更多相关文章

  1. CodeForces 567B Berland National Library

    Description Berland National Library has recently been built in the capital of Berland. In addition, ...

  2. CodeForces 567B Berland National Library hdu-5477 A Sweet Journey

    这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可 #include<cstdio> #include<cstring ...

  3. Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟

    B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  4. Codeforces B - Berland National Library

    B. Berland National Library time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. Codeforces Round #Pi (Div. 2) B. Berland National Library set

    B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  6. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  7. Codeforces Round #Pi (Div. 2) B Berland National Library

    B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...

  8. Berland National Library

    题目链接:http://codeforces.com/problemset/problem/567/B 题目描述: Berland National Library has recently been ...

  9. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

随机推荐

  1. javaSE高级篇4 — 反射机制( 含类加载器 ) — 更新完毕

    反射机制 1.反射机制是什么?----英文单词是:reflect.在java.lang包下---这才是java最牛逼的技术 首先提前知道一句话----在java中,有了对象,于是有了类,那么有了类之后 ...

  2. absent, absolute, absorb

    absent Absenteeism is a habitual [习惯性的] pattern of absence from a duty or obligation [职责] without go ...

  3. Hadoop【MR开发规范、序列化】

    Hadoop[MR开发规范.序列化] 目录 Hadoop[MR开发规范.序列化] 一.MapReduce编程规范 1.Mapper阶段 2.Reducer阶段 3.Driver阶段 二.WordCou ...

  4. jenkins的sonarqube之代码检测的两种方法

    #:sonarqube下载地址,我们安装6.7  高版本已经不支持MySQL和Mariadb(最小3G内存) https://www.sonarqube.org/downloads/ #:安装文档 h ...

  5. zabbix之源码安装

    #:官网地址 https://www.zabbix.com/documentation/4.0/zh/manual/installation/install #:解压并创建用户 root@ubuntu ...

  6. Spring Cloud服务离线

    服务离线,即某服务不能对外提供服务了.服务离线的原因有两种:服务下架与服务下线.这两种方案都是基于Actuator监控器实现的. 服务下架:将注册到Eureka Server中的Eureka Clie ...

  7. vue实现input输入框的模糊查询

     最近在用uni-app做一个项目,使用的框架还是vue,想了好久才做出来 . HTML代码部分 <input type="text" focus class="s ...

  8. VueAPI 2 (生命周期钩子函数)

    所有的生命周期钩子自动绑定 this 上下文到实例中,因此你可以访问数据,对属性和方法进行运算.这意味着你不能使用箭头函数来定义一个生命周期方法. beforeCreate 在实例初始化之后,此时还不 ...

  9. FastDFS的理解和分析

    FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载均衡的问题.特别适合以文件为载体的在线服务,如相 ...

  10. UVA10079 Pizza Cutting 题解

    Content 求用 \(n\) 条直线最多能将平面分成多少块区域. 多组输入,以一个负数结束. 数据范围:\(0\leqslant n\leqslant 2.1\times 10^8\). Solu ...