Submission #21282608


Source Code Expand

Copy
// watashi ha Row of Tents de taore mashita yurusanai

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const L = readLong();
      auto X = new long[N];
      auto A = new long[N];
      foreach (i; 0 .. N) {
        X[i] = readLong();
        A[i] = readLong();
      }
      
      bool check(long b0) {
        long bef = 0;
        long b = b0;
        foreach (i; 0 .. N) {
          b = min(b + (X[i] - bef), b0);
          b -= A[i];
          if (b < 0) {
            return false;
          }
          bef = X[i];
        }
        return true;
      }
      
      long lo = -1, hi = 10L^^18;
      for (; lo + 1 < hi; ) {
        const mid = (lo + hi) / 2;
        (check(mid) ? hi : lo) = mid;
      }
      writeln(hi);
    }
  } catch (EOFException e) {
  }
}

Submission Info

Submission Time
Task A - Row of Tents
User hos_lyric
Language D (LDC 1.20.1)
Score 100
Code Size 2032 Byte
Status AC
Exec Time 111 ms
Memory 14540 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 26
Set Name Test Cases
sample sample_00, sample_01
All continuous_00, continuous_01, continuous_02, corner, max_00, max_01, max_02, max_03, max_04, max_05, max_06, max_07, max_08, max_09, random_00, random_01, random_02, random_03, random_04, sample_00, sample_01, small_00, small_01, small_02, small_03, small_04
Case Name Status Exec Time Memory
continuous_00 AC 67 ms 5792 KB
continuous_01 AC 94 ms 6768 KB
continuous_02 AC 52 ms 8056 KB
corner AC 4 ms 3168 KB
max_00 AC 103 ms 7064 KB
max_01 AC 110 ms 14540 KB
max_02 AC 108 ms 6996 KB
max_03 AC 105 ms 6960 KB
max_04 AC 111 ms 14436 KB
max_05 AC 111 ms 14408 KB
max_06 AC 109 ms 7176 KB
max_07 AC 103 ms 7144 KB
max_08 AC 105 ms 7012 KB
max_09 AC 107 ms 6904 KB
random_00 AC 46 ms 4856 KB
random_01 AC 38 ms 4652 KB
random_02 AC 28 ms 4328 KB
random_03 AC 48 ms 5184 KB
random_04 AC 66 ms 7256 KB
sample_00 AC 6 ms 3328 KB
sample_01 AC 4 ms 3288 KB
small_00 AC 3 ms 3164 KB
small_01 AC 4 ms 3232 KB
small_02 AC 3 ms 3364 KB
small_03 AC 3 ms 3220 KB
small_04 AC 5 ms 3108 KB