n,m=gets.split(" ").map{|e| e.to_i}xs=gets.split(" ").map{|e| e.to_i}ys=[0]s=0xs.each{|e| s+=e ys<<s}p ysm.times{ l,r=gets.split(" ").map{|e| e.to_i} puts xs[l-1]-ys[r]+ys[l]}
8 9 1 9 2 3 7 3 6 5 1 5 5 6 1 8 2 5 4 8 1 6 2 4 3 4 7 8
[0, 1, 10, 12, 15, 22, 25, 31, 36] -20 4 -34 -3 -18 -23 4 -1 1
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!