(POJ) 1852--ants (ANT)

Source: Internet
Author: User

Describe
The ants ' armies walk on the horizontal poles of the length LCM, each with a constant speed of 1cm/s. When a walking ant reaches one end of the pole, it drops immediately. When two ants meet, they return and start moving in the opposite direction. We know the original position of the ant on the pole, unfortunately, we don't know the direction of the ant walking. Your task is to calculate the shortest and longest possible time for all ants to get out of the pole.


Input
The first line of input contains an integer that gives the number of cases. The data for each case starts with two integers: the length of the pole (in cm), and n is the number of ants on the pole. These two numbers follow the n integers, giving the position of each ant on the pole as the distance measured from the left side of the bar, without a specific order. All input integers are not greater than 1000000, and they are separated by spaces.


Output
For each case input, the output is two digits separated by a space. The first number is the earliest possible time for all ants to leave the pole (if their direction of walk is chosen appropriately), the second number is the longest possible such time.


Sample input
2
10 3
2 6 7
214 7
11 12 7 13 176 23 191


Sample output
4 8
38 207

This topic can ignore the collision of ants, will each ant's Movement shortest time and the longest time to seek out, respectively take inside the maximum value.

1#include <iostream>2#include <cstdio>3#include <algorithm>4 5 using namespacestd;6 7 intMain ()8 {9     intt,x,i;Tenscanf"%d",&t); One      while(t--) A     { -         intL,n,max_time=0, min_time=0; -scanf"%d%d",&l,&n); the          for(i=1; i<=n;i++) -         { -scanf"%d",&x); -Max_time=max (Max_time,max (x,l-x)); +Min_time=max (Min_time,min (x,l-x)); -         } +printf"%d%d\n", min_time,max_time); A     } at     return 0; -}
Answer

(POJ) 1852--ants (ANT)

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.