fork download
  1. # your code goes here
  2. import sys
  3.  
  4. def solution1(n, numbers):
  5. numbers.sort()
  6. answer = 0
  7.  
  8. for k in range(n):
  9. sumation = numbers[k]
  10. i = n-1 # n-1, idx
  11.  
  12. for idx in range(n): # 0 ~
  13. if idx == k:
  14. continue
  15.  
  16. while numbers[idx] + numbers[i] > sumation or i == k:
  17. i -= 1
  18. print(i)
  19. if idx >= i:
  20. break
  21.  
  22. if numbers[idx] + numbers[i] == sumation:
  23. answer += 1
  24. break
  25.  
  26. return answer
  27.  
  28. N = int(sys.stdin.readline())
  29. arr = list(map(int, sys.stdin.readline().split()))
  30.  
  31. print(solution1(6, arr))
Runtime error #stdin #stdout #stderr 0.13s 25984KB
stdin
6
1 10 10 10 10 10
stdout
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
stderr
Traceback (most recent call last):
  File "./prog.py", line 31, in <module>
  File "./prog.py", line 16, in solution1
IndexError: list index out of range