結果

問題 No.649 ここでちょっとQK!
ユーザー Mr.SpockMr.Spock
提出日時 2020-12-26 21:44:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 3,000 ms
コード長 683 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 171,236 KB
実行使用メモリ 12,888 KB
最終ジャッジ日時 2023-10-25 06:30:09
合計ジャッジ時間 7,547 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 257 ms
4,348 KB
testcase_04 AC 151 ms
12,888 KB
testcase_05 AC 160 ms
12,888 KB
testcase_06 AC 138 ms
12,888 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 79 ms
7,276 KB
testcase_13 AC 79 ms
7,276 KB
testcase_14 AC 78 ms
7,244 KB
testcase_15 AC 88 ms
7,316 KB
testcase_16 AC 75 ms
7,684 KB
testcase_17 AC 97 ms
7,940 KB
testcase_18 AC 110 ms
8,324 KB
testcase_19 AC 117 ms
8,660 KB
testcase_20 AC 134 ms
9,060 KB
testcase_21 AC 146 ms
9,412 KB
testcase_22 AC 158 ms
9,824 KB
testcase_23 AC 174 ms
10,168 KB
testcase_24 AC 186 ms
10,564 KB
testcase_25 AC 205 ms
10,940 KB
testcase_26 AC 218 ms
11,288 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 67 ms
7,268 KB
testcase_31 AC 72 ms
7,544 KB
testcase_32 AC 2 ms
4,348 KB
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(val1);
			}
		} 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