大水题一道。用tmp记录当前在阅览室的人的人数。
如果遇到直接出去没进来的,就在已有的ans上+1。表示以前就在里面。
表示纯模拟15ms就跑完了。。
#include<iostream>
using namespace std;
const int maxl=1000000;
int ans,tmp,n,num;
char a;
bool flag[maxl+1];
void read()
{
int i;
std::ios::sync_with_stdio(false);
cin>>n;
for(i=1; i<=n; i++)
{
cin>>a>>num;
if(a=='+')
{
tmp++;
flag[num]=true;
}
else
if(flag[num]==false)
ans++;
else
{
flag[num]=false;
tmp--;
}
ans=max(ans,tmp);
}
cout<<ans;
return;
}
int main()
{
read();
return 0;
}