Skip to content

Instantly share code, notes, and snippets.

@harsh-2024
Created September 17, 2022 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harsh-2024/29e551596367876d1fee7158c539f0d1 to your computer and use it in GitHub Desktop.
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
#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;
}
@harsh-2024
Copy link
Author

sol uploaded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment