The most time is the longest crawl that every ant chooses.
The least time is every ant chooses the quickest way to crawl.
#include <iostream> #include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #include <queue> #include <vector> #include <algorithm >using namespace Std;int main () {int A,b,i,t,len,n,t;cin>>t;while (t--) {Cin>>len>>n;a=b=0;while (n--) {Cin>>t;a=max (A,min (len-t,t)); B=max (B,max (len-t,t));} cout<<a<< "" <<b<<endl;} return 0;}
Ants
Time Limit:3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format:%lld &%llu |
Submit Status
Description
Problem B:antsan army of ants walk on a horizontal pole of length
LCM, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When the ants meet they turn back and the start walking in opposite directions. We know the original positions of ants on the pole, unfortunately, we don't know the directions in which the ants is Wal King. Your task is to compute the earliest and the latest possible times needed for all ants to fall off the pole.
The first line of input contains one integer giving the number of cases that follow. The data for each case start with both integer numbers:the length of the pole (in cm) andn, the number of ants re Siding on the pole. These numbers is followed byn integers giving the position of all ant on the pole as the distance measured From the left end of the pole, in no particular order. All input integers is not bigger than 1000000 and they is separated by whitespace.
For each case of input, output of the numbers separated by a single space. The first number is the earliest possible time, all ants fall off, the pole (if the directions of their walks are chose n appropriately) and the second number is the latest possible such time.
Sample input
210 32 6 7214 711 12 7 13 176 23 191
Output for sample input
4 838 207
Piotr Rudnicki
Source
Root:: Competitive programming 3:the New Lower Bound of programming contests (Steven & Felix Halim):: Problem Solvi Ng Paradigms:: Greedy:: Non classical, usually harder
Root:: AOAPC i:beginning algorithm Contests (Rujia Liu):: Volume 4. Algorithm Design
Root:: Competitive programming 2:this increases the lower bound of programming contests. Again (Steven & Felix Halim):: Problem Solving Paradigms:: Greedy-standard
Root:: Prominent problemsetters:: Piotr Rudnicki
UVA-10714 Ants