Challenge: Sort by growth
Input
- The first line of each query contains one number n (1 ≤ n ≤ 20000) - the number of members in corresponding delegation.
- The second line contains n unsorted integers - the heights of athletes in centimeters. Every height is at least 150 cm, and no greater than 250 cm.
- The third line contains a and b: the lower and upper height limits.
Output
For each query print the count on a separate line.
Time limit: 2 seconds
Memory limit: 256 MiB
My program works correctly, but I have a running time of 3020 ms.
import java.io.PrintWriter;
import java.util.Scanner;
public class OlimpGames {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out, true);
{
while (in.hasNextInt()) {
int n = in.nextInt();
int heigh[] = new int[100];
for (int i = 0; i < n; i++) {
heigh[in.nextInt() - 150]++;
}
int a = in.nextInt();
int b = in.nextInt();
int an = 0;
for (int i = a - 150; i <= b - 150; i++) {
an = an + heigh[i];
}
System.out.println(an);
}
}
}
}