結果

問題 No.649 ここでちょっとQK!
ユーザー Mr.SpockMr.Spock
提出日時 2020-12-26 21:39:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 682 bytes
コンパイル時間 2,991 ms
コンパイル使用メモリ 170,156 KB
実行使用メモリ 12,900 KB
最終ジャッジ日時 2023-10-25 06:25:41
合計ジャッジ時間 8,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 250 ms
4,348 KB
testcase_04 AC 149 ms
12,900 KB
testcase_05 AC 160 ms
12,900 KB
testcase_06 AC 138 ms
12,900 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll q, k;
	cin >> q >> k;
	multiset<ll>m1, m2;
	for (ll i = 0; i < q; i++) {
		ll type;
		cin >> type;
		if (type == 1) {
			ll val;
			cin >> val;
			m1.insert(val);
			if (m1.size() > k) {
				ll val1 = *m1.rbegin();
				m1.erase(m1.find(val1));
				m2.insert(val);
			}
		} else {
			if (m1.size() != k)
				cout << "-1" << endl;
			else {
				ll val1 = *m1.rbegin();
				cout << val1 << endl;
				m1.erase(m1.find(val1));
				if (m2.size() >= 1) {
					ll val2 = *m2.begin();
					m2.erase(m2.find(val2));
					m1.insert(val2);
				}
			}
		}
	}
}
0