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

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, just forward to ask you how much time to dial, you can make all the table time

Exercises

Sort + maintain prefixes and, violence out of the smallest on OK

Code

1#include <cstdio>2#include <cmath>3#include <cstring>4#include <ctime>5#include <iostream>6#include <algorithm>7#include <Set>8#include <vector>9#include <sstream>Ten#include <queue> One#include <typeinfo> A#include <fstream> -#include <map> -#include <stack> the typedef __int64 LL; - using namespacestd; - inline ll read () - { +ll x=0, f=1; -     CharCh=GetChar (); +      while(ch<'0'|| Ch>'9') A     { at         if(ch=='-') f=-1; -Ch=GetChar (); -     } -      while(ch>='0'&&ch<='9') -     { -x=x*Ten+ch-'0'; inCh=GetChar (); -     } to     returnx*F; + } - //************************************************************************************** thell t=1000000; * intN; $ll sum[200000];Panax Notoginsengll a[200000]; - intMain () the { +  Ascanf"%d",&n); the      for(intI=1; i<=n; i++) +     { - ll H,m,s; $Cin>>h>>m>>s; $a[i]=s+m*t+t*t*h; -     } -Sort (A +1, a+n+1); the      for(intI=1; i<=n;i++) -sum[i]=sum[i-1]+A[i];Wuyill tt= A*t*T; thell ans=tt*1000000;//This place is infinitely large. -          Wu      for(inti=n;i>=1; i--) -     { Aboutll xx= (a[i]* (i-1)-sum[i-1]+ (A[I]+TT) * (n-i)-(sum[n]-sum[i])); $cn1=min (xx,ans); -     } -printf"%i64d%i64d%i64d\n", (ans/t)/T, (ans/t)%t,ans%t); -     return 0; A}
View Code

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

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.