-
Notifications
You must be signed in to change notification settings - Fork 0
/
1714A - Everyone Loves to Sleep.cpp
94 lines (75 loc) · 1.83 KB
/
1714A - Everyone Loves to Sleep.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 1e7;
int x[MAX];
int y[MAX];
int s;
ll n;
bool st(const pair<int, int> &p1, const pair<int, int> &p2)
{
if (p1.first != p2.first)
return p1.first < p2.first;
return p1.second < p2.second;
}
void solve()
{
int n, h, m;
cin >> n >> h >> m;
vector<pair<int, int>> v;
vector<pair<int, int>> v2;
for (int i = 0; i < n; i++)
{
int ht, mt;
cin >> ht >> mt;
if ((ht < h) || (ht == h && mt < m))
{
v2.push_back(make_pair(ht, mt));
continue;
}
v.push_back(make_pair(ht, mt));
}
if (v.size() > 0)
{
sort(v.begin(), v.end(), st);
int hh, mm;
if (v[0].second - m < 0)
{
cout << v[0].first - h - 1 << ' ' << v[0].second - m + 60 << '\n';
}
else
{
cout << v[0].first - h << ' ' << v[0].second - m << '\n';
}
}
else
{
sort(v2.begin(), v2.end(), st);
reverse(v2.begin(), v2.end());
// if (v2[v2.size() - 1].second - m < 0)
// {
// cout << v2[v2.size() - 1].first - h - 1 << ' ' << v[0].second - m + 60 << '\n';
// }
// else
// {
// cout << v[0].first - h << ' ' << v[0].second - m << '\n';
// }
if (60 - m + v2[v2.size() - 1].second > 59)
{
cout << 23 - h + v2[v2.size() - 1].first + 1 << ' ' << -m + v2[v2.size() - 1].second << '\n';
return;
}
cout << 23 - h + v2[v2.size() - 1].first << ' ' << 60 - m + v2[v2.size() - 1].second << '\n';
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
return EXIT_SUCCESS;
}