// Arup Guha
// 5/25/2010
// Solution to 2010 AP Computer Science Free Response Problem #3

public class Trail {
	
	private int[] markers;
	
	public Trail(int[] elevation) {
		markers = elevation;
	}
	
	// Solution to Part A.
	public boolean isLevelTrailSegment(int start, int end) {
		
		// Set initial values.
		int max = markers[start];
		int min = markers[start];
		
		// Update these using the usual algorithm.
		for (int i=start+1; i<=end; i++) {
			if (markers[i] > max)
				max = markers[i];
			if (markers[i] < min)
				min = markers[i];
		}
		
		// This is their criteria for a level trail segment.
		return max-min <= 10;
	}
	
	public boolean isDifficult() {
		
		int numOver30 = 0;
		
		// Go through each gap, make sure you end before length-1.
		for (int i=0; i<markers.length-1; i++) {
			
			// If it's over 30 (don't forget abs), add one.
			if (Math.abs(markers[i+1]-markers[i]) >= 30)
				numOver30++;
		}
		
		// Criterion for being difficult.
		return numOver30 >= 3;
	}
	
	public static void main(String[] args) {
		
		int[] elevation = {100, 150, 105, 120, 90, 80, 50, 75, 75, 70, 80, 90, 100};
		
		Trail thisTrail = new Trail(elevation);
		
		// This is their test.
		if (thisTrail.isLevelTrailSegment(7,10))
			System.out.println("This part of the trail is level.");
		
		// I added this so we could see something that isn't level.
		if (!thisTrail.isLevelTrailSegment(7,11))
			System.out.println("But adding segment 11 makes it not level.");
			
		// This is their test again.
		if (thisTrail.isDifficult())
			System.out.println("This trail is difficult.");
			
		// I added this one so we have one easy trail to test.
		int[] easyTrail = {90, 110, 81, 51, 80, 110, 139, 120, 100};
		Trail easy = new Trail(easyTrail);
		
		if (!easy.isDifficult())
			System.out.println("And this trail is easy!");
	}
}