I wrote the following solution in CF #72 for Problem B in Ruby:
- n, k = gets.split.map{|_|_.to_i}
- a = gets.split.map{|_|_.to_i}
- b = a.sort
- if (a.length == 1 ? a[0] : a.inject{|x,y| x + y}) <= k
- puts -1
- else
- i = 0
- s = 0
- while (b[i] - s) * (n - i) <= k
- k -= (b[i] - s) * (n - i)
- s = b[i]
- i += 1
- end
- while b[i] - s == 0
- i += 1
- end
- t = k / (n - i)
- k -= t * (n - i)
- j = 0
- while k > 0
- if a[j] >= b[i]
- a[j] -= 1
- k -= 1
- end
- j += 1
- end
- ans = ""
- for k in j...n
- if a[k] > t + s
- ans += (k + 1).to_s + " "
- end
- end
- for k in 0...j
- if a[k] > t + s
- ans += (k + 1).to_s + " "
- end
- end
- puts ans.strip
- end
It worked fine on my computer, but on the server, it fails for case 5:
Test: #5, time: 80 ms., memory: 3408 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER
Input
1 1 1
Output
-1
Answer
Checker Log
wrong answer Output contains longer sequence [length = 1], but answer contains 0 elements
Any Ruby gurus have a clue?
In the problem statement:
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or print one "End of line"-character. Both will be accepted.