import strutils, sequtils, algorithm var A = newSeq[int]() i, cnt, best = 0 let NK = stdin.readLine.split.map parseInt (N, K) = (NK[0], NK[1]) for i in 0 ..< N: A.add stdin.readLine.parseInt A.sort(cmp, Descending) while i < A.len: cnt += A[i] if cnt <= K: i += 1 best = max(cnt, best) else: i = 0 cnt = 0 A.del(0) echo best