program main implicit none integer*8::N,A,B,W,i,j integer*8,allocatable::D(:) integer*8,allocatable::dp(:,:) read *, N,A,B,W allocate(D(N)) allocate(dp(0:N,0:N)) read *, D dp(0,0) = W dp(1,0) = W + D(1) dp(1,1) = MAX(W - A + B*1,0) do i=2,N dp(i,0) = MINVAL(dp(i-1,0:i-1)) + D(i) do j=1,i dp(i,j) = MAX(dp(i-1,j-1) - A + B*j,0) end do end do print '(i0)', MINVAL(dp(N,0:N)) end program