Submission #3404560


Source Code Expand

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

const INF* = int(1e18 + 373)

proc readSeq*(): seq[string] = stdin.readLine().strip().split()
proc readSeq*(n: Natural): seq[string] =
  result = newSeq[string](n)
  for i in 0..<n:
    result[i] = stdin.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])

type seq2*[T] = seq[seq[T]]
proc newSeq2*[T](n1, n2: Natural): seq2[T] = newSeqWith(n1, newSeq[T](n2))

#------------------------------------------------------------------------------#
type Person = tuple [ h, p: int ]

proc `<`(p1, p2: Person): bool =
  (p1.h + p1.p) < (p2.h + p2.p)

proc main() =
  let n = readInt1()
  var ps = newSeq[Person](n)
  for i in 0..<n:
    ps[i] = readInt2()
  ps.sort(cmp[Person])

  var dp = newSeq2[int](n + 1, n + 1)
  dp[0].fill(INF)
  dp[0][0] = 0

  for i in 1..n:
    for j in 0..n:
      var opt = dp[i - 1][j]
      if j > 0 and dp[i - 1][j - 1] <= ps[i - 1].h:
       opt = min(opt, dp[i - 1][j - 1] + ps[i - 1].p)
      dp[i][j] = opt

  var ans = -1
  for j in countdown(n, 0):
    if dp[n][j] != INF:
      ans = j
      break
  echo ans

main()

Submission Info

Submission Time
Task D - Zabuton
User somq14
Language Nim (0.13.0)
Score 0
Code Size 1559 Byte
Status MLE
Exec Time 450 ms
Memory 404656 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: logging [Processing]
lib/pure/logging.nim(128, 22) Hint: 'Exception' is declared but not used [XDeclaredButNotUsed]
Hint: future [Processing]
Hint: macros [Processing]
Hint:  [Link]
Hint: operation successful (24852 lines compiled; 2.652 sec total; 25.256MB; Release Build) [SuccessX]

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 16
MLE × 30
Set Name Test Cases
sample sample-01.txt, sample-02.txt, sample-03.txt
All sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 1 ms 256 KB
01-02.txt AC 1 ms 380 KB
01-03.txt AC 30 ms 30204 KB
01-04.txt AC 104 ms 98300 KB
01-05.txt MLE 433 ms 404220 KB
01-06.txt MLE 434 ms 404220 KB
01-07.txt MLE 434 ms 404220 KB
01-08.txt MLE 435 ms 404220 KB
01-09.txt MLE 434 ms 404220 KB
01-10.txt AC 1 ms 256 KB
01-11.txt AC 17 ms 15100 KB
01-12.txt AC 154 ms 145020 KB
01-13.txt MLE 416 ms 391932 KB
01-14.txt MLE 436 ms 404220 KB
01-15.txt MLE 436 ms 404220 KB
01-16.txt MLE 436 ms 404220 KB
01-17.txt MLE 436 ms 404220 KB
01-18.txt MLE 450 ms 404656 KB
01-19.txt AC 1 ms 256 KB
01-20.txt AC 13 ms 12412 KB
01-21.txt AC 210 ms 195708 KB
01-22.txt MLE 437 ms 403196 KB
01-23.txt MLE 439 ms 404220 KB
01-24.txt MLE 440 ms 404220 KB
01-25.txt MLE 440 ms 404220 KB
01-26.txt MLE 439 ms 404220 KB
01-27.txt MLE 439 ms 404220 KB
01-28.txt MLE 433 ms 404220 KB
01-29.txt MLE 433 ms 404220 KB
01-30.txt MLE 434 ms 404220 KB
01-31.txt MLE 433 ms 404220 KB
01-32.txt MLE 433 ms 404220 KB
01-33.txt MLE 435 ms 404220 KB
01-34.txt MLE 433 ms 404220 KB
01-35.txt MLE 442 ms 404220 KB
01-36.txt MLE 442 ms 404220 KB
01-37.txt MLE 442 ms 404220 KB
01-38.txt MLE 442 ms 404220 KB
01-39.txt MLE 442 ms 404220 KB
01-40.txt MLE 433 ms 404220 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt AC 1 ms 256 KB