fork(1) download
  1. n = int(raw_input())
  2. b = [0 for i in range(n)]
  3. for i in range(n):
  4. b[i] = int(raw_input())
  5. a = [0]
  6. for sumDig in b:
  7. suff = 0
  8. for x in a:
  9. suff += x
  10. for i in range(10000):
  11. if len(a) == i:
  12. a.append(0)
  13. suff -= a[i]
  14. found = False
  15. for dig in range(a[i] + 1, 10):
  16. if dig + suff <= sumDig and sumDig <= dig + suff + i * 9:
  17. a[i] = dig
  18. need = sumDig - dig - suff
  19. for t in range(0, i):
  20. a[t] = min(need, 9)
  21. need -= a[t]
  22. found = True
  23. break
  24. if found:
  25. break
  26. res = ''
  27. ok = False
  28. for i in range(len(a) - 1, -1, -1):
  29. if a[i] != 0:
  30. ok = True
  31. if ok:
  32. res += str(a[i])
  33. print res
Runtime error #stdin #stdout #stderr 0.01s 7736KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 1, in <module>
EOFError: EOF when reading a line