結果
問題 |
No.649 ここでちょっとQK!
|
ユーザー |
|
提出日時 | 2018-02-11 18:27:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 258 ms / 3,000 ms |
コード長 | 1,061 bytes |
コンパイル時間 | 603 ms |
コンパイル使用メモリ | 70,004 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-11-17 10:18:04 |
合計ジャッジ時間 | 5,846 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <cmath> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define repR(i, n) for(int i = (n) - 1; i > -1; i--) #define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++) #define rep1R(i, n) for(int i = (n); i > 0; i--) typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); multiset<ll> S, T; ull Q, K; cin >> Q >> K; // cout << "Q:" << Q << " K:" << K << endl; rep(i, Q) { int q; cin >> q; if (q == 1) { ll v; cin >> v; if (S.size() < K - 1) S.insert(v); else if (S.empty()) T.insert(v); else if (v >= *S.rbegin()) T.insert(v); else { S.insert(v); ll tmp = *(--S.end()); S.erase(--S.end()); T.insert(tmp); } } else if (q == 2) { if (!T.empty()) { ll tmp = *T.begin(); T.erase(T.begin()); cout << tmp << endl; } else { cout << -1 << endl; } } } return 0; }