Advertisement
PikMike

Untitled

Feb 22nd, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. inp = open("input.txt")
  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() + ' '
  9.     t = ""
  10.     for j in range(len(s)):
  11.         if (s[j] == '-') and (len(t) == 0):
  12.             t += s[j]
  13.         elif (s[j].isdigit()):
  14.             t += s[j]
  15.     a.append(int(t))
  16.  
  17. a.sort()
  18.  
  19. open("output.txt", "w").write(str(sum(a[:k])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement