time limit per test : 1 secondios
memory limit per test : 256 megabytesc++
input : standard inputapi
output : standard outputui
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.this
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:spa
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.code
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.orm
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.ip
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).ci
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.
Print a single integer — the minimum possible capacity of the reading room.
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; }