-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_fridges.cpp
49 lines (46 loc) · 1.04 KB
/
two_fridges.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
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
int n;
priority_queue<pair<int,int>> substancias;
cin >> n;
if(n==0){
cout << -100 << " " << -100;
return 0;
}
int geladeira1;
int geladeira2;
int contador = 0;
for(int i = 0; i< n; i++){
int t1, t2;
cin >> t1 >> t2;
substancias.push({t1,t2});
}
if(n==1){
geladeira1 = substancias.top().first;
geladeira2 = -100;
}
else{
geladeira1 = substancias.top().first;
substancias.pop();
geladeira2 = substancias.top().first;
while(!substancias.empty()){
substancias.pop();
if(geladeira2 > substancias.top().second){
geladeira2 = substancias.top().first;
if(n == 3){
contador ++;
}
if(contador == 1){
cout << -1;
return 0;
}
contador++;
}
}
}
cout << geladeira2 << " " << geladeira1;
return 0;
}