-
Notifications
You must be signed in to change notification settings - Fork 3
/
a.cpp
37 lines (37 loc) · 796 Bytes
/
a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int k, n;
cin >> k >> n;
vector<int> Y(n+k-1);
auto P = Y;
auto order = Y;
for (int i = 0; i < Y.size(); ++i) {
cin >> Y[i] >> P[i];
order[i] = i;
}
priority_queue<tuple<int,int>> pq;
sort(order.begin(), order.end(), [&](int a, int b) {
return Y[a] < Y[b];
});
for (int i = 0; i+1< k; ++i) {
int j = order[i];
pq.emplace(P[j], j);
}
bool impossible = true;
for (int i = k-1; i < Y.size(); ++i) {
int j = order[i];
pq.emplace(P[j], j);
auto [p, x] = pq.top();
if (x == 0) {
impossible = false;
cout << Y[j] << endl;
break;
}
pq.pop();
}
if (impossible) cout << "unknown" << endl;
return 0;
}