给出n组数据, + 代表进入图书馆, - 相反,问图书馆最少可能容量。
先统计出 + 的数据,遇到 - 若已经在图书馆则不算这个人,若不在图书馆容量加1。
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int maxn = 1e6 + 5;
int main(int argc, char const *argv[])
{
int n, ans = 0, x, num = 0;
char c;
bool a[maxn] = {false};
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> c >> x;
if(c == '+') {
a[x] = true;
num++;
ans = max(ans, num);
}
else {
if(a[x]) num--;
if(!a[x]) ans++;
}
}
cout << ans << endl;
return 0;
}