import macros;macro ImportExpand(s:untyped):untyped = parseStmt($s[2]) {.checks: off.} import sequtils proc scanf(formatstr: cstring){.header: "", varargs.} proc ii(): int {.inline.} = scanf("%lld\n", addr result) var n, p, k = ii() var tb = newSeqWith(n, (ii(), ii())) var dp = newSeqWith(k+1, -1) dp[0] = p const mx = 1000_000_000_000_000_000 for (t, b) in tb: var dpn = dp for i in 0.. mx: echo -1 quit() dpn[i+1] = max(dpn[i+1], dp[i] * 2) swap(dp, dpn) # must be WA echo dp[^1]