結果

問題 No.649 ここでちょっとQK!
ユーザー ldsybldsyb
提出日時 2018-02-09 23:07:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 3,000 ms
コード長 824 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 169,728 KB
実行使用メモリ 6,044 KB
最終ジャッジ日時 2024-04-17 06:05:01
合計ジャッジ時間 6,521 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 303 ms
5,376 KB
testcase_04 AC 196 ms
6,044 KB
testcase_05 AC 180 ms
5,852 KB
testcase_06 AC 191 ms
5,580 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 103 ms
5,376 KB
testcase_13 AC 100 ms
5,376 KB
testcase_14 AC 98 ms
5,376 KB
testcase_15 AC 102 ms
5,376 KB
testcase_16 AC 101 ms
5,376 KB
testcase_17 AC 115 ms
5,376 KB
testcase_18 AC 125 ms
5,376 KB
testcase_19 AC 135 ms
5,376 KB
testcase_20 AC 146 ms
5,376 KB
testcase_21 AC 158 ms
5,376 KB
testcase_22 AC 168 ms
5,376 KB
testcase_23 AC 179 ms
5,376 KB
testcase_24 AC 188 ms
5,376 KB
testcase_25 AC 199 ms
5,376 KB
testcase_26 AC 207 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 63 ms
5,376 KB
testcase_31 AC 66 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int q, k;
	cin >> q >> k;
	priority_queue<int64_t> pq;
	priority_queue<int64_t, vector<int64_t>, greater<>> s;
	for (int i = 0; i < q; i++) {
		int f;
		cin >> f;
		if (f == 1) {
			int64_t v;
			cin >> v;
			if (pq.size() == k && pq.top() < v) {
				s.emplace(v);
			} else {
				if (pq.size() == k) {
					s.emplace(pq.top());
					pq.pop();
				}
				pq.emplace(v);
			}
		} else {
			if (pq.size() + s.size() < k) {
				cout << -1 << endl;
			} else {
				while (pq.size() < k && !s.empty()) {
					pq.emplace(s.top());
					s.pop();
				}
				cout << pq.top() << endl;
				pq.pop();
			}
		}
		while (!pq.empty() && !s.empty() && s.top() < pq.top()) {
			int64_t x = s.top(), y = pq.top();
			s.pop();
			pq.pop();
			pq.emplace(x);
			s.emplace(y);
		}
	}
}
0