// Alien // AIO 2011 // C# Sample Solution using System; using System.IO; using System.Text; public class Solution { /* These are the limits as defined in the problem statement. */ public const int MAX_HUMANS = 100000; public const int MAX_WIDTH = 1000000; /* n is the number of humans. */ private static int n; /* w is the width of the beam. */ private static int w; /* * The p[] array will contain the positions of each of the humans, as * described in the problem statement. The first position is stored in p[0]. */ private static int[] p = new int[MAX_HUMANS]; public static void Main() { /* Open the input and output files. */ TextReader inputFile = File.OpenText("alienin.txt"); TextWriter outputFile = File.CreateText("alienout.txt"); /* Read the values of N and W from the input file. */ string input = inputFile.ReadLine(); string[] bits = input.Split(' '); n = int.Parse(bits[0]); w = int.Parse(bits[1]); /* Read the values of p_i into the p array. */ for (int i = 0; i < n; i++) { p[i] = int.Parse(inputFile.ReadLine()); } /* Calculate the answer. */ int answer = 0; int first = 0; int last = 0; for (last = 0; last < n; last++) { while (p[last]-p[first] >= w) first++; if (answer < last - first + 1) answer = last - first + 1; } /* Write the answer to the output file. */ outputFile.WriteLine(answer); /* Finally, close the input/output files. */ inputFile.Close(); outputFile.Close(); } }