Codeforces 567B:Berland National Library(模拟)

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;
}
原文地址:https://www.cnblogs.com/Friends-A/p/11686091.html