Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace prB {
- class Program {
- #if ONLINE_JUDGE
- private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
- private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
- #else
- private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
- private static readonly StreamReader reader = new StreamReader(@"..\..\input");
- #endif
- static void Main(string[] args) {
- int n = NextInt();
- int[] a = new int[n];
- for (int i = 0; i < n; i++) {
- a[i] = NextInt();
- }
- Array.Sort(a);
- int k1 = a[n - 1] - a[1];
- int k2 = a[n - 2] - a[0];
- writer.Write(Math.Min(k1, k2));
- writer.Flush();
- #if !ONLINE_JUDGE
- writer.Close();
- #endif
- }
- private static int NextInt() {
- int c;
- int res = 0;
- do {
- c = reader.Read();
- if(c == -1)
- return res;
- } while(c != '-' && (c < '0' || c > '9'));
- int sign = 1;
- if(c == '-') {
- sign = -1;
- c = reader.Read();
- }
- res = c - '0';
- while(true) {
- c = reader.Read();
- if(c < '0' || c > '9')
- return res * sign;
- res *= 10;
- res += c - '0';
- }
- }
- private static long NextLong() {
- int c;
- long res = 0;
- do {
- c = reader.Read();
- if(c == -1)
- return res;
- } while(c != '-' && (c < '0' || c > '9'));
- int sign = 1;
- if(c == '-') {
- sign = -1;
- c = reader.Read();
- }
- res = c - '0';
- while(true) {
- c = reader.Read();
- if(c < '0' || c > '9')
- return res * sign;
- res *= 10;
- res += c - '0';
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement