HackerRank

The punch line to this problem is the support to very very large int handling. I tried C++ code for multiple times, but it only passed first 13~ cases.

Then I tried Ruby and got it passed all:

meta = gets.chomp
nm = meta.split(' ')
n = nm.first.to_i
m = nm.last.to_i

total = 0
for i in 0..m-1
   triple = gets.chomp
   vs = triple.split(' ')
   vs = vs.map(&:to_i)
   total += vs[2] * (vs[1] - vs[0] + 1)   
end

puts total / n

However, there are a bunch of all-passing C++ solutions. I also used 'long long' actually... weird

原文地址:https://www.cnblogs.com/tonix/p/4303333.html