diff --git a/AcWing/830/830.cpp b/AcWing/830/830.cpp new file mode 100644 index 00000000..95d74700 --- /dev/null +++ b/AcWing/830/830.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int n, a; +stack st; + +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + while (!st.empty() && st.top() >= a) st.pop(); + if (st.empty()) { + cout << -1 << ' '; + } else { + cout << st.top() << ' '; + } + st.push(a); + } + cout << endl; + return 0; +}