integer::N,D,i,j=0,place=1,mx,M(4) integer,allocatable,dimension(:)::T,K integer,allocatable,dimension(:,:)::sum read *,N,D allocate(T(N),K(N),sum(2,N)) do i=1,N read *,T(i),K(i) end do sum(1,0)=0 sum(2,0)=-D do i=1,N sum(1,i)=max(sum(1,i-1),sum(2,i)-D)+T(i) sum(2,i)=max(sum(2,i-1),sum(1,i)-D)+K(i) end do print *,max(sum(1,N),sum(2,N)) end