Submission #1008622


Source Code Expand

Copy
N, x = gets.split.map &:to_i
A = gets.split.map &:to_i
A.concat([0])

ans = 0
N.times do |i|
  a, b = A[i], A[i+1]
  #p a:a, b:b
  if a+b > x
    d = (a+b)-x
    db = [d, b].min
    da = [d-b, 0].max
    ans += d
    A[i+1] -= db
  end
end
p ans

Submission Info

Submission Time
Task C - Boxes and Candies
User yhara
Language Ruby (2.3.3)
Score 300
Code Size 263 Byte
Status
Exec Time 147 ms
Memory 11148 KB

Compile Error

./Main.rb:1: warning: `&' interpreted as argument prefix
./Main.rb:2: warning: `&' interpreted as argument prefix
./Main.rb:12: warning: assigned but unused variable - da

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 300 / 300 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt
Case Name Status Exec Time Memory
0_00.txt 10 ms 1788 KB
0_01.txt 10 ms 1788 KB
0_02.txt 10 ms 1788 KB
0_03.txt 10 ms 1788 KB
1_00.txt 10 ms 1788 KB
1_01.txt 10 ms 1788 KB
1_02.txt 10 ms 1788 KB
1_03.txt 10 ms 1788 KB
1_04.txt 53 ms 7676 KB
1_05.txt 53 ms 7676 KB
1_06.txt 147 ms 11148 KB
1_07.txt 110 ms 11148 KB
1_08.txt 136 ms 11020 KB
1_09.txt 135 ms 11020 KB
1_10.txt 131 ms 11020 KB
1_11.txt 104 ms 11020 KB
1_12.txt 139 ms 11020 KB
1_13.txt 142 ms 11020 KB
1_14.txt 141 ms 11020 KB
1_15.txt 141 ms 11020 KB