Salvens

E

Jul 27th, 2023
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <array>
  2. #include <iostream>
  3. #include <vector>
  4. #include <map>
  5. #include <queue>
  6. #include <set>
  7. #include <stack>
  8.  
  9. using namespace std;
  10.  
  11. #define int long long
  12.  
  13. const long long INF = 1e18 + 7;
  14. const int MAXN = 2e5 + 10;
  15. const int N = 1e5 + 10;
  16.  
  17. int n, k, p;
  18. //array<stack<int>, N> a;
  19.  
  20. signed main() {
  21.     ios_base::sync_with_stdio(false);
  22.     cin.tie(nullptr);
  23.     cout.tie(nullptr);
  24.     cin >> n >> k >> p;
  25.     int cnt = 0, maxi = 0;
  26.     vector<stack<int>> a(k);
  27.     for (int i = 0; i < n; ++i) {
  28.         char type;
  29.         int pos, x;
  30.         cin >> type >> pos >> x;
  31.         --pos;
  32.         if (type == '+') {
  33.             a[pos].push(x);
  34.             ++cnt;
  35.             maxi = max(maxi, cnt);
  36.             if (cnt > p) {
  37.                 cout << "Error";
  38.                 return 0;
  39.             }
  40.         } else {
  41.             if (a[pos].empty() || a[pos].top() != x) {
  42.                 cout << "Error";
  43.                 return 0;
  44.             }
  45.             a[pos].pop();
  46.             --cnt;
  47.         }
  48.     }
  49.     if (cnt) {
  50.         cout << "Error";
  51.         return 0;
  52.     } else {
  53.         cout << maxi << '\n';
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment