fork download
  1. # paiza POH! Vol.1
  2. # result:
  3. # http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/e6151191448a2d892579fb21f0f1a4bb
  4. # author: Leonardone @ NEETSDKASU
  5. nd = raw_input().split(" ")
  6. n = int(nd[0])
  7. d = int(nd[1])
  8. p = []
  9. for i in range(0, n):
  10. p.append(int(raw_input()))
  11. p.sort()
  12. ci = (n - 1) >> 1
  13. cp = p[ci]
  14. for i in range(0, d):
  15. m = int(raw_input())
  16. if m < cp:
  17. f = ci
  18. else:
  19. f = n - 1
  20. if m - p[ci] > cp:
  21. e = ci
  22. else:
  23. e = 0
  24. tmp = 0
  25. while f != e:
  26. sum = p[f] + p[e]
  27. if sum > m:
  28. f = f - 1
  29. else:
  30. if sum > tmp:
  31. tmp = sum
  32. e = e + 1
  33. print tmp
  34.  
Success #stdin #stdout 0.01s 7856KB
stdin
5 2
4000
3000
1000
2000
5000
10000
3000
stdout
9000
3000