This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int borne = 301*1000;
int nbOp;
// + : undo / - : edit
int tab[borne];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> nbOp;
for (int i = 0; i < nbOp; ++i) {
cin >> tab[i];
tab[i] = -tab[i];
if (i > 0) cout << "0\n";
}
vector<pii> pile;
for (int iOp = nbOp-1; iOp >= 0; --iOp) {
int lvl = max(0, tab[iOp]);
if (pile.empty() || lvl >= pile.back().first) {
pile.push_back({lvl, -tab[iOp]});
} else {
pile.pop_back();
}
}
if (pile.empty() || pile.front().first > 0) {
cout << "0\n";
} else {
cout << pile.front().second << "\n";
}
}
# | 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... |