#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll n, q, x, ans = 0;
    cin >> n >> q;
    ll a[n]{};
    bool b[n]{};
    while(q--)
    {
        cin >> x;
        if (x < 0)
        {
            b[-x] = false;
            a[-x] = max(a[-x], ans);
        }
        else
        {
            a[x] = max(a[x], ans-1);
            if (b[x])
            {
                a[x]++;
                ans = max(ans, a[x]);
            }
            b[x] = true;
        }
    }
    cout << ans << "\n";
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |