-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
46 lines (42 loc) · 891 Bytes
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define ERR(...) fprintf(stderr, __VA_ARGS__)
constexpr int N = 1e5 + 10;
int ans[N], ans_sz;
int main() {
int n;
scanf("%d", &n);
vector<int> oper;
for (int i = 0; i < 2 * n; ++i) {
char c;
scanf(" %c", &c);
if (c == '+') {
oper.push_back(1);
} else {
int x;
scanf("%d", &x);
oper.push_back(-x);
}
}
reverse(oper.begin(), oper.end());
set<int> st;
auto Fuck = [] { puts("NO"); exit(0); };
for (auto& op : oper) {
if (op > 0) {
if (st.empty()) Fuck();
ans[ans_sz++] = *st.begin();
st.erase(st.begin());
} else {
if (!st.empty() && *st.begin() < -op) Fuck();
st.insert(-op);
}
}
reverse(ans, ans + ans_sz);
puts("YES");
for (int i = 0; i < ans_sz; ++i) {
printf("%d ", ans[i]);
}
return 0;
}