Codeforces Gym 100637A A. Nano alarm-clocks prefix and

Source: Internet
Author: User

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/gym/100637/problem/A

Description

An old watchmaker have n stopped nano alarm-clocks numbered with integers from 1 to n. Nano alarm-clocks count time in hours, and in one hour there is million minutes, each minute lasting a million seconds. In order to repair them all the watchmaker should synchronize the time on all nano alarm-clocks. In order to do the He moves clock hands a certain time forward (may be zero time). Let's name this time shift a transfer time.

Your task is to calculate the minimal total transfer time required for all Nano alarm-clocks to show the same time.

Input

The first line contains a single integer n  -the number of Nano alarm-clocks (2≤ n ≤10< Span class= "Upper-index" >5). In Each  i -th of the Next  n  lines the Time  h ,   m , s , shown on The  i -th clock. Integers  h ,   m  and  s  show the number of hours, minutes and seconds respectively. (0≤ H < 12, 0≤ m < 106,0≤ s < 106).

Output

Output three integers separated with spaces h, m and s -total minimal transfer Tim E, where h, m and s -number of hours, minutes and seconds respectively ( 0≤ m < 6, 0≤ s <6).

Sample Input

2
10 0 0
3 0 0

Sample Output

5 0 0

HINT

Test instructions

Give you n a clock, ask you how much time to turn, can make all the table the same time

Note that you can only forward

Exercises

Sort first, then maintain the prefix and, for each table in front of him, maybe time can only go to the same time as he did

At the back of his watch, he turned to his time +12h just fine

and run it all over again.

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************unsignedLong Longti[maxn];unsignedLong LongSUM[MAXN];intMain () {intn=read ();  for(intI=1; i<=n;i++) {unsignedLong LongX=read (), Y=read (), z=read (); Ti[i]=z+y*1000000ll+x*1000000ll*1000000LL; } Sort (Ti+1, ti+1+N);  for(intI=1; i<=n;i++) Sum[i]=sum[i-1]+Ti[i]; unsignedLong Longans=0;  for(intI=1; i<=n;i++) {unsignedLong Longnum=i*ti[i]-Sum[i]; Num+ = (12ll*1000000ll*1000000ll+ti[i]) * (n-i)-sum[n]+Sum[i]; if(i==1) ans=num; Elseans=min (ans,num); } unsignedLong Longhour=1000000ll*1000000LL; unsignedLong Longh=ans/(1000000ll*1000000LL); unsignedLong LongM= (ans-h* (1000000LL*1000000LL))/1000000LL; unsignedLong Longs=ans-h*1000000ll*1000000ll-m*1000000LL; cout<" "<<m<<" "<<s<<Endl;}

Codeforces Gym 100637A A. Nano alarm-clocks prefix and

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.