import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc solve()= var n = scan() vw = newseqwith(n,(scan(),scan())) v = scan() m = 100000 dp = newseqwith(2,newseqwith(m+1,0)) for i in 1..n: var now = i.mod(2) prev = (i+1).mod(2) for w in 0..100000: if w-vw[i-1][1]>=0: dp[now][w].max=max(dp[prev][w],dp[prev][w-vw[i-1][1]]+vw[i-1][0]) else: dp[now][w].max=dp[prev][w] var minw = int.high maxw = 0 for w in 1..m: if dp[n.mod(2)][w] == v: minw.min=w maxw.max=w echo minw if maxw==m: echo "inf" else: echo maxw solve()