Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <iostream>
- #include <vector>
- #include <map>
- #include <queue>
- #include <set>
- #include <stack>
- using namespace std;
- #define int long long
- const long long INF = 1e18 + 7;
- const int MAXN = 2e5 + 10;
- const int N = 1e5 + 10;
- int n, k, p;
- //array<stack<int>, N> a;
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- cin >> n >> k >> p;
- int cnt = 0, maxi = 0;
- vector<stack<int>> a(k);
- for (int i = 0; i < n; ++i) {
- char type;
- int pos, x;
- cin >> type >> pos >> x;
- --pos;
- if (type == '+') {
- a[pos].push(x);
- ++cnt;
- maxi = max(maxi, cnt);
- if (cnt > p) {
- cout << "Error";
- return 0;
- }
- } else {
- if (a[pos].empty() || a[pos].top() != x) {
- cout << "Error";
- return 0;
- }
- a[pos].pop();
- --cnt;
- }
- }
- if (cnt) {
- cout << "Error";
- return 0;
- } else {
- cout << maxi << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment