Ultraviolet A-10714 ants

Source: Internet
Author: User
Tags integer numbers

The maximum time is the longest crawling method selected by each ant


The minimum time is the fastest crawling method for each ant

#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:3000 Ms   Memory limit:Unknown   64bit Io format:% LLD & % LlU

Submitstatus

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 two ants meet they turn back and start walking in opposite directions. we know the original positions of ants on the pole, unfortunately, we do not know the directions in which the ants are walking. 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 two integer numbers: the length of the pole (in cm) andN, The number of ants residing on the pole. These two numbers are followedNIntegers giving the position of each ant on the pole as the distance measured from the left end of the pole, in no particle order. all input integers are not bigger than 1000000 and they are separated by whitespace.

For each case of input, output two numbers separated by a single space. the first number is the earliest possible time when all ants fall off the pole (if the ctions of their walks are chosen 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 Solving 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

Ultraviolet A-10714 ants

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.