Advertisement
PlotnikovPhilipp

Untitled

Oct 25th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import math
  3. amountOfStones = int(input())
  4. stones = [int(i) for i in input().split()]
  5. stones.sort(reverse=True)
  6. halfSum = math.ceil(sum(stones) / 2)
  7. maximum = 0
  8. i = 0
  9. while i < len(stones):
  10.     if maximum + stones[i] > halfSum:
  11.         i += 1
  12.         continue
  13.     else:
  14.         maximum += stones[i]
  15.     i += 1
  16. print(abs(sum(stones) - 2*maximum))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement