-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_Everyone_Loves_to_Sleep.cpp
136 lines (128 loc) · 3.73 KB
/
A_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
//**************************************************************************************************************************************************************************
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//**************************************************************************************************************************************************************************
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-9
#define inf 1e18
#define sz(x) (int)((x).size())
#define gcd(a, b) __gcd(a, b)
#define LCM(x, y) (((x) / __gcd((x), (y))) * (y))
#define mem(x, n) memset(x, n, sizeof(x))
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x, y) fixed << setprecision(y) << x
#define All(x) (x).begin(), (x).end()
//**************************************************************************************************************************************************************************
char gap = 32;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
os << '{';
for (const auto &x : v)
os << gap << x;
return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
return os << '(' << p.first << gap << p.second << ')';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
cerr << ' ' << H;
dbg_out(T...);
}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << '(' << #__VA_ARGS__ << ')' << ':', dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
typedef tree<int, null_type, less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//*************************************************************************************************************************************************************************
void c_p_c()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
void solve()
{
int n, h,m;
cin>>n>>h>>m;
vector<pair<int, int>>v(n);
for(int i = 0;i<n;i++)
{
cin>>v[i].first>>v[i].second;
}
sort(v.begin(), v.end());
for(int i = 0;i<n;i++)
{
if(v[i].first == h && v[i].second == m)
{
cout<<0<<" "<<0<<endl;
return;
}
if(v[i].first == h && v[i].second> m)
{
cout<<0<<" "<<v[i].second - m<<endl;
return;
}
if(v[i].first>h )
{
if(v[i].second>=m)
{
cout << v[i].first - h << " " << v[i].second - m << endl;
return;
}
else
{
cout << v[i].first - h -1<< " " << 60 - m + v[i].second<< endl;
return;
}
}
}
if(v[0].second>=m)
{
cout<<24 - (h - v[0].first)<<" "<<v[0].second - m<<endl;
}
else
cout << 24 - (h - v[0].first) - 1 << " " << 60-(m - v[0].second)<< endl;
}
int main(int argc, char const *argv[])
{
// c_p_c();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
#endif
int t = 1;
cin >> t;
for (int i = 0; i < t; i++)
solve();
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
}