結果

問題 No.649 ここでちょっとQK!
ユーザー CELICA
提出日時 2020-10-16 08:12:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 65 ms / 3,000 ms
コード長 828 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 173,644 KB
実行使用メモリ 5,940 KB
最終ジャッジ日時 2024-07-20 20:20:02
合計ジャッジ時間 6,334 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll q, k;
	cin >> q >> k;
	priority_queue<ll> ql;
	priority_queue<ll, vector<ll>, greater<ll> > qr;
	stringstream ss;
	for (ll i = 0; i < q; ++i)
	{
		int t;
		cin >> t;

		if (t == 1)
		{
			ll v;
			cin >> v;

			if ((int)ql.size() < k)
				ql.push(v);
			else
			{
				ll qlt = ql.top();
				if (qlt > v)
				{
					ql.pop();
					ql.push(v);
					qr.push(qlt);
				}
				else
					qr.push(v);
			}
		}
		else
		{
			if ((int)ql.size() >= k)
			{
				ss << ql.top() << "\n";
				ql.pop();
				if (!qr.empty())
				{
					ql.push(qr.top());
					qr.pop();
				}
			}
			else
				ss << "-1\n";

		}
	}

	cout << ss.str();

	return 0;
}
0