Submission #2690468


Source Code Expand

import java.io.*;
import java.util.*;
 
 
public class Main implements Runnable {

  @SuppressWarnings("unchecked") 
  public void run() {
    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();
    int z = scanner.nextInt();
    int w = scanner.nextInt();

    long[] aa = new long[n];
    for (int i = 0 ; i < n ; i ++) {
      aa[i] = scanner.nextInt();
    }

    if (n <= 1) {
      long res = Math.abs(w - aa[0]);
      System.out.println(res);
      return;
    }

    long[] xMins = new long[n - 1];
    long[] yMaxs = new long[n - 1];

    xMins[n - 2] = Math.abs(aa[n - 1] - aa[n - 2]);
    yMaxs[n - 2] = Math.abs(aa[n - 1] - aa[n - 2]);

    for (int i = n - 3 ; i >= 0 ; i --) {
      long x = Math.max(yMaxs[i + 1], Math.abs(aa[i] - aa[n - 1]));
      xMins[i] = Math.min(x, xMins[i + 1]);
      long y = Math.min(xMins[i + 1], Math.abs(aa[i] - aa[n - 1]));
      yMaxs[i] = Math.max(y, yMaxs[i + 1]);
    }

    long res = Math.max(yMaxs[0], Math.abs(w - aa[n - 1]));
    System.out.println(res);
  }

  public static void main(String[] args) {
    Main main = new Main();
    main.run();
  }
 
  public static class BetterScanner {
 
    private InputStream stream;
    private byte[] buffer = new byte[1024];
    private int pointer = 0;
    private int bufferLength = 0;
 
    public BetterScanner(InputStream stream) {
      this.stream = stream;
    }
 
    private boolean updateBuffer() {
      if (pointer >= bufferLength) {
        pointer = 0;
        try {
          bufferLength = stream.read(buffer);
        } catch (IOException exception) {
          exception.printStackTrace();
        }
        return bufferLength > 0;
      } else {
        return true;
      }
    }
 
    private int read() {
      if (updateBuffer()) {
        return buffer[pointer ++];
      } else {
        return -1;
      }
    }
 
    public boolean hasNext() {
      skipUnprintable();
      return updateBuffer();
    }
 
    private void skipUnprintable() { 
      while (updateBuffer() && !isPrintableChar(buffer[pointer])) {
        pointer ++;
      }
    }
 
    public String next() {
      if (hasNext()) {
        StringBuilder builder = new StringBuilder();
        int codePoint = read();
        while (isPrintableChar(codePoint)) {
          builder.appendCodePoint(codePoint);
          codePoint = read();
        }
        return builder.toString();
      } else {
        throw new NoSuchElementException();
      }
    }
 
    public long nextLong() {
      if (hasNext()) {
        long number = 0;
        boolean minus = false;
        int codePoint = read();
        if (codePoint == '-') {
          minus = true;
          codePoint = read();
        }
        if (codePoint >= '0' && codePoint <= '9') {
          while (true) {
            if (codePoint >= '0' && codePoint <= '9') {
              number *= 10;
              number += codePoint - '0';
            } else if (codePoint < 0 || !isPrintableChar(codePoint)) {
              return (minus) ? -number : number;
            } else {
              throw new NumberFormatException();
            }
            codePoint = read();
          }
        } else {
          throw new NumberFormatException();
        }
      } else {
        throw new NoSuchElementException();
      }
    }
 
    public int nextInt() {
      long number = nextLong();
      if (number >= Integer.MIN_VALUE && number <= Integer.MAX_VALUE) {
        return (int)number;
      } else {
        throw new NumberFormatException();
      }
    }
 
    private boolean isPrintableChar(int codePoint) {
      return codePoint >= 33 && codePoint <= 126;
    }
 
  }
 
}

Submission Info

Submission Time
Task D - ABS
User ziphil
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 3811 Byte
Status AC
Exec Time 146 ms
Memory 24788 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 28
Set Name Test Cases
Sample example_0, example_1, example_2, example_3
All example_0, example_1, example_2, example_3, one_0, one_1, one_2, one_3, one_4, one_5, one_6, one_7, rand_0, rand_1, rand_10, rand_11, rand_12, rand_13, rand_14, rand_15, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9
Case Name Status Exec Time Memory
example_0 AC 92 ms 19924 KB
example_1 AC 92 ms 21844 KB
example_2 AC 92 ms 19284 KB
example_3 AC 91 ms 18772 KB
one_0 AC 92 ms 21844 KB
one_1 AC 91 ms 18644 KB
one_2 AC 91 ms 21588 KB
one_3 AC 92 ms 21844 KB
one_4 AC 93 ms 19668 KB
one_5 AC 91 ms 19796 KB
one_6 AC 93 ms 19412 KB
one_7 AC 92 ms 21844 KB
rand_0 AC 146 ms 24404 KB
rand_1 AC 128 ms 21332 KB
rand_10 AC 141 ms 21716 KB
rand_11 AC 128 ms 19540 KB
rand_12 AC 138 ms 21972 KB
rand_13 AC 146 ms 24788 KB
rand_14 AC 143 ms 22476 KB
rand_15 AC 113 ms 19284 KB
rand_2 AC 129 ms 23380 KB
rand_3 AC 126 ms 21332 KB
rand_4 AC 144 ms 23404 KB
rand_5 AC 127 ms 22356 KB
rand_6 AC 142 ms 24148 KB
rand_7 AC 139 ms 22868 KB
rand_8 AC 139 ms 22612 KB
rand_9 AC 137 ms 23892 KB