Advertisement
PikMike

Untitled

Feb 22nd, 2017
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. inp = open("input.txt", "rb")
  2.  
  3. n, k = [int(x) for x in inp.readline().split()]
  4.  
  5. a = []
  6.  
  7. for i in range(n):
  8.     s = inp.readline() + b' '
  9.     t = ""
  10.     for j in s:
  11.         if (j == ord('-')) and (len(t) == 0):
  12.             t += chr(j)
  13.         elif (j >= ord('0')) and (j <= ord('9')):
  14.             t += chr(j)
  15.     a.append(int(t))
  16.  
  17. a.sort()
  18.  
  19. #print(a)
  20.  
  21. open("output.txt", "w").write(str(sum(a[:k])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement