結果

問題 No.649 ここでちょっとQK!
ユーザー momoharamomohara
提出日時 2019-11-12 20:19:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 270 ms / 3,000 ms
コード長 1,850 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 94,584 KB
実行使用メモリ 12,996 KB
最終ジャッジ日時 2023-10-19 11:42:24
合計ジャッジ時間 7,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 270 ms
4,348 KB
testcase_04 AC 108 ms
12,996 KB
testcase_05 AC 103 ms
12,996 KB
testcase_06 AC 105 ms
12,996 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 70 ms
7,380 KB
testcase_13 AC 70 ms
7,380 KB
testcase_14 AC 68 ms
7,348 KB
testcase_15 AC 73 ms
7,420 KB
testcase_16 AC 76 ms
7,788 KB
testcase_17 AC 85 ms
8,044 KB
testcase_18 AC 93 ms
8,428 KB
testcase_19 AC 102 ms
8,764 KB
testcase_20 AC 112 ms
9,164 KB
testcase_21 AC 122 ms
9,516 KB
testcase_22 AC 130 ms
9,928 KB
testcase_23 AC 144 ms
10,272 KB
testcase_24 AC 156 ms
10,668 KB
testcase_25 AC 168 ms
11,044 KB
testcase_26 AC 174 ms
11,392 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 60 ms
7,372 KB
testcase_31 AC 63 ms
7,648 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll q, k;
	cin >> q >> k;

	multiset<ll> st;
	
	auto it = st.begin();

	while (q--) {
		ll t;
		cin >> t;
		if (t == 1) {
			ll v;
			cin >> v;
			st.insert(v);
			if (st.size() == k&&it!=st.begin()) {
				it = st.end();
				it--;
			}
			else if(st.size()>k){
				if (*it > v) {
					it--;
				}
			}
		}
		else {
			if (st.size() >= k) {
				cout << *it << endl;
				it = st.erase(it);
			}
			else {
				cout << -1 << endl;
			}
		}
	}


	return 0;
}
0