結果

問題 No.649 ここでちょっとQK!
コンテスト
ユーザー vjudge1
提出日時 2026-05-02 11:10:38
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 85 ms / 3,000 ms
コード長 676 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,097 ms
コンパイル使用メモリ 161,792 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2026-05-02 11:10:44
合計ジャッジ時間 5,329 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<set>
using namespace std;
#define int long long
const int N = 2e5 + 5;

int q,k;
multiset<int> s1,s2;

signed main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> q >> k;
	while(q--)
	{
		int opt, x; cin >> opt;
		if(opt == 1)
		{
			cin >> x;
			if(s1.size() < k) s1.insert(x);
			else if(x < *(--s1.end()))
			{
				s2.insert(*(--s1.end()));
				s1.erase(--s1.end());
				s1.insert(x);
			}
			else s2.insert(x);
		}
		else
		{
			if(s1.size() < k) cout << -1 << '\n';
			else
			{
				cout << *(--s1.end()) << '\n';
				s1.erase(--s1.end());
				if(s2.size()) s1.insert(*s2.begin()), s2.erase(s2.begin());
			}
		}
	}
	return 0;
}
0