-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnigs.cpp
More file actions
62 lines (55 loc) · 1.45 KB
/
Copy pathKnigs.cpp
File metadata and controls
62 lines (55 loc) · 1.45 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <queue>
using namespace std;
struct knig{
int year;
int strength;
};
struct yearComparison{
bool operator()( const knig& a, const knig& b ) {
return a.year > b.year;
}
};
struct strengthComparison{
bool operator()( const knig& a, const knig& b ) {
return a.strength < b.strength;
}
};
int main(void){
int size, years;
cin >> size >> years;
knig KA;
cin >> KA.year >> KA.strength;
priority_queue<knig, vector<knig>, yearComparison> incomingPool;
priority_queue<knig, vector<knig>, strengthComparison> contestantPool;
if(KA.year == 2011)
contestantPool.push(KA);
else
incomingPool.push(KA);
for(int i = 0; i < size + years - 2; i ++){
knig newcoming;
cin >> newcoming.year >> newcoming.strength;
if(newcoming.year == 2011)
contestantPool.push(newcoming);
else
incomingPool.push(newcoming);
}
int currentYear = 2011;
bool isKing = false;
for(int i = 0; i < years; i ++){
knig newking = contestantPool.top();
if(newking.strength == KA.strength){
isKing = true;
break;
}
contestantPool.pop();
currentYear ++;
knig newcomer = incomingPool.top();
contestantPool.push(newcomer);
incomingPool.pop();
}
if(isKing)
cout << currentYear << endl;
else
cout << "unknown" << endl;
}