fork(1) download
  1. # paiza POH! Vol.1
  2. # result:
  3. # http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/55f03f8ad372afbe1e1d38ee46275a98
  4. # author: Leonardone @ NEETSDKASU
  5. s = gets.split(' ')
  6. n = s[0].to_i
  7. d = s[1].to_i
  8. p = []
  9. n.times do |i|
  10. p[i] = gets.to_i
  11. end
  12. p = p.sort
  13.  
  14. d.times do
  15. m = gets.to_i
  16. i = 0
  17. j = n - 1
  18. tmp = 0
  19. while i != j
  20. sum = p[i] + p[j]
  21. if sum > m then
  22. j = j - 1
  23. else
  24. tmp = sum if sum > tmp
  25. i = i + 1
  26. end
  27. end
  28. puts tmp
  29. end
Success #stdin #stdout 0.01s 7412KB
stdin
5 2
4000
3000
1000
2000
5000
10000
3000
stdout
9000
3000