Created
September 17, 2022 08:14
-
-
Save harsh-2024/29e551596367876d1fee7158c539f0d1 to your computer and use it in GitHub Desktop.
This is the solution of the third question of the Reload22 Coding Contest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
int t; | |
cin >> t; | |
while(t--){ | |
int n,h,m,done=0; | |
cin >> n >> h >> m; | |
vector<pair<int,int>> alarms; | |
for(int i =0;i<n;i++){ | |
int ah=0,am=0; | |
pair<int,int> temp; | |
cin >> ah >> am; | |
temp.first = ah; | |
temp.second = am; | |
alarms.push_back(temp); | |
} | |
for(int i=0;i<n;i++){ | |
if(alarms[i].first == h && alarms[i].second == m){ | |
cout << 0 << " " << 0 << endl; | |
done = 1; | |
break; | |
} | |
} | |
if(!done){ | |
int temp = INT_MAX; | |
int tmin =0; | |
for(int i =0;i<n;i++){ | |
int fh = alarms[i].first; | |
int fm = alarms[i].second; | |
if((fh*100+fm) < (h*100 + m)){ | |
tmin = (2400-(h*100 + m)) + (fh*100+fm) - (fh*40) - ((24-h)*40); | |
} | |
else{ | |
tmin = ( ( (fh*100) + fm ) - ( (h*100) + m ) ) - ((fh-h)*40) ; | |
} | |
temp = min(tmin,temp); | |
} | |
cout << (temp/60) << " " << (temp%60) << endl; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sol uploaded