#include using namespace std; #define int long long signed main(){ int H,W; cin>>H>>W; H -= 2; vector> A(H,vector(W)); for(int i=0;i>A[i][j]; if(A[i][j] == -1) A[i][j] = 1e18; } vector> dp(H,vector(W,1e18)); for(int i=0;i,vector>,greater>> pq; for(int j=0;j w+A[u-1][i]){ dp[u-1][i] = w+A[u-1][i]; pq.push({dp[u-1][i],u-1}); } } if(u != H-1){ if(dp[u+1][i] > w+A[u+1][i]){ dp[u+1][i] = w+A[u+1][i]; pq.push({dp[u+1][i],u+1}); } } } for(int j=0;j