Ants.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package acm;
import java.util.Scanner;
/**
*
* @author cteam030
*/
public class Ants {
public static void main
(String[] args
) {
Scanner s
= new Scanner
(System.
in);
while(s.hasNext())
{
int d = s.nextInt();
int count = s.nextInt();
int max = 0;
int middle1 = -1;
int middle2 = -1;
for(int i = 0; i < count; i++)
{
int pos = s.nextInt();
int len = dir.equals("R") ? d - pos : pos;
if(len > max)
{
max = len;
}
double delta
= Math.
abs(pos
- d
/2); if(delta
< Math.
abs(middle2
- d
/2)) {
if(delta
< Math.
abs(middle1
- d
/2)) {
middle2 = middle1;
middle1 = pos;
}else
{
middle2 = pos;
}
}
}
System.
out.
printf("The last ant will fall down in %d seconds - started at %d", max, middle1
);
if(middle2 >= 0)
{
System.
out.
printf(" and %d", middle2
); }
}
}
}