Advertisement
T-D-K

Untitled

Dec 27th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. namespace prB {
  6.     class Program {
  7. #if ONLINE_JUDGE
  8.         private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
  9.         private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
  10. #else
  11.         private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
  12.         private static readonly StreamReader reader = new StreamReader(@"..\..\input");
  13. #endif
  14.  
  15.         static void Main(string[] args) {
  16.             int n = NextInt();
  17.             int[] a = new int[n];
  18.             for (int i = 0; i < n; i++) {
  19.                 a[i] = NextInt();
  20.             }
  21.             Array.Sort(a);
  22.             int k1 = a[n - 1] - a[1];
  23.             int k2 = a[n - 2] - a[0];
  24.             writer.Write(Math.Min(k1, k2));
  25.             writer.Flush();
  26. #if !ONLINE_JUDGE
  27.             writer.Close();
  28. #endif
  29.         }
  30.         private static int NextInt() {
  31.             int c;
  32.             int res = 0;
  33.             do {
  34.                 c = reader.Read();
  35.                 if(c == -1)
  36.                     return res;
  37.             } while(c != '-' && (c < '0' || c > '9'));
  38.             int sign = 1;
  39.             if(c == '-') {
  40.                 sign = -1;
  41.                 c = reader.Read();
  42.             }
  43.             res = c - '0';
  44.             while(true) {
  45.                 c = reader.Read();
  46.                 if(c < '0' || c > '9')
  47.                     return res * sign;
  48.                 res *= 10;
  49.                 res += c - '0';
  50.             }
  51.         }
  52.         private static long NextLong() {
  53.             int c;
  54.             long res = 0;
  55.             do {
  56.                 c = reader.Read();
  57.                 if(c == -1)
  58.                     return res;
  59.             } while(c != '-' && (c < '0' || c > '9'));
  60.             int sign = 1;
  61.             if(c == '-') {
  62.                 sign = -1;
  63.                 c = reader.Read();
  64.             }
  65.             res = c - '0';
  66.             while(true) {
  67.                 c = reader.Read();
  68.                 if(c < '0' || c > '9')
  69.                     return res * sign;
  70.                 res *= 10;
  71.                 res += c - '0';
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement