$O(n\lg n)$
#include<cstdio> #include<queue> using namespace std; priority_queue<int> pq; int n, x; int main() { for (scanf("%d", &n); n--;) { scanf("%d", &x); if (x) pq.push(x); else if (pq.empty()) puts("0"); else printf("%d\n", pq.top()), pq.pop(); } return 0; }
댓글 없음 :
댓글 쓰기