input n input k dim a(1 to k) for i = 1 to k input a(i) next i for i = 1 to k for j = i + 1 to k if a(i) > a(j) then t = a(i) a(i) = a(j) a(j) = t endif next j next i r = 0 for i = 1 to k if n >= a(i) then n = n - a(i) r = r + 1 endif next i print r