Last active
May 11, 2016 04:53
-
-
Save wbars/838f0e2c3b8778b1a78802e68245b5be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.OutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.PrintWriter; | |
import java.util.Scanner; | |
/** | |
* Built using CHelper plug-in | |
* Actual solution is at the top | |
* | |
* @author wannabe | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
InputStream inputStream = System.in; | |
OutputStream outputStream = System.out; | |
Scanner in = new Scanner(inputStream); | |
PrintWriter out = new PrintWriter(outputStream); | |
Taller solver = new Taller(); | |
solver.solve(1, in, out); | |
out.close(); | |
} | |
static class Taller { | |
public void solve(int testNumber, Scanner in, PrintWriter out) { | |
int n = in.nextInt(); | |
int[] days = new int[n]; | |
for (int i = 0; i < n; i++) { | |
days[i] = in.nextInt(); | |
} | |
if (days.length == 1) { | |
out.println(days[0]); | |
return; | |
} | |
int max = Math.max(days[0], days[days.length - 1]); | |
int min = Math.min(days[0], days[days.length - 1]); | |
for (int i = 0; i < n; i++) { | |
if (days[i] < min) { | |
min = days[i]; | |
} else { | |
if (days[i] > max) { | |
max = days[i]; | |
} | |
} | |
} | |
out.println(max - min); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment