Submission #3820106


Source Code Expand

import strutils
import sequtils
import algorithm
import math
import queues
import tables
import sets
import future

const INF* = int(1e18 + 373)

proc readLine*(): string =
  stdin.readLine()
proc readSeq*(): seq[string] =
  readLine().strip().split()
proc readSeq*(n: Natural): seq[string] =
  result = newSeq[string](n)
  for i in 0..<n:
    result[i] = readLine().strip()
proc readInt1*(): int =
  readSeq().map(parseInt)[0]
proc readInt2*(): (int, int) =
  let a = readSeq().map(parseInt)
  return (a[0], a[1])
proc readInt3*(): (int, int, int) =
  let a = readSeq().map(parseInt)
  return (a[0], a[1], a[2])
proc readInt4*(): (int, int, int, int) =
  let a = readSeq().map(parseInt)
  return (a[0], a[1], a[2], a[3])
proc newSeqWith*[T](n: Natural; e: T): seq[T] =
  result = newSeq[T](n)
  for i in 0..<n:
    result[i] = e
type seq2*[T] = seq[seq[T]]
proc newSeq2*[T](n1, n2: Natural): seq2[T] =
  newSeqWith(n1, newSeq[T](n2))
type seq3*[T] = seq[seq[seq[T]]]
proc newSeq3*[T](n1, n2, n3: Natural): seq3[T] =
  newSeqWith(n1, newSeqWith(n2, newSeq[T](n3)))

#------------------------------------------------------------------------------#
type Pred1[T] = T -> bool

# [lb, ub)
proc nibutanLb(lb, ub: int; f: Pred1[int]): int =
  var lb = lb
  var ub = ub
  while ub - lb > 1:
    let mid = (ub + lb) div 2
    if f(mid):
      lb = mid
    else:
      ub = mid
  return lb

# (lb, ub]
proc nibutanUb(lb, ub: int; f: Pred1[int]): int =
  var lb = lb
  var ub = ub
  while ub - lb > 1:
    let mid = (ub + lb) div 2
    if f(mid):
      ub = mid
    else:
      lb = mid
  return ub
#------------------------------------------------------------------------------#
proc subr(n: int; ws, ds: seq[int]; x: int): int =
  var sum = 0
  for i in 0..<n:
    if ws[i] > x:
      continue
    sum += 1 + (x - ws[i]) div ds[i]
  return sum

proc main() =
  let (n, k) = readInt2()
  var ws = newSeq[int](n)
  var ds = newSeq[int](n)
  for i in 0..<n:
    (ws[i], ds[i]) = readInt2()

  let ans = nibutanUb(0, (2e18 + 1).int(), it => (subr(n, ws, ds, it) >= k))
  echo ans

main()

Submission Info

Submission Time
Task C - Garden
User somq14
Language Nim (0.13.0)
Score 100
Code Size 2165 Byte
Status AC
Exec Time 139 ms
Memory 1916 KB

Compile Error

Hint: system [Processing]
Hint: Main [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: sequtils [Processing]
Hint: algorithm [Processing]
Hint: math [Processing]
Hint: times [Processing]
Hint: queues [Processing]
Hint: tables [Processing]
Hint: hashes [Processing]
Hint: etcpriv [Processing]
Hint: sets [Processing]
Hint: os [Processing]
Hint: posix [Processing]
Hint: future [Processing]
Hint: macros [Processing]
Main.nim(46, 6) Hint: 'Main.nibutanLb(lb: int, ub: int, f: Pred1[system.int])' is declared but not used [XDeclaredButNotUsed]
Hint:  [Link]
Hint: operation successful (24569 lines compiled; 2.130 sec total; 23.235MB; Release Build) [SuccessX]

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 23
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 139 ms 1916 KB
b06 AC 136 ms 1916 KB
b07 AC 138 ms 1916 KB
b08 AC 138 ms 1916 KB
b09 AC 138 ms 1916 KB
b10 AC 139 ms 1916 KB
b11 AC 81 ms 1916 KB
b12 AC 83 ms 1916 KB
b13 AC 86 ms 1916 KB
b14 AC 93 ms 1916 KB
b15 AC 81 ms 1916 KB
b16 AC 84 ms 1916 KB
b17 AC 87 ms 1916 KB
b18 AC 95 ms 1916 KB
b19 AC 79 ms 1916 KB
b20 AC 81 ms 1916 KB
b21 AC 88 ms 1916 KB
b22 AC 89 ms 1916 KB
b23 AC 105 ms 1916 KB