// I SELL YOU...! #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; using TP = tuple; void init_io(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } const ll INF = 1e9; signed main(){ init_io(); ll h,w; cin >> h >> w; vector> a(h, vector(w, -1)); vector> dp(h, vector(w, INF)); for(int i=1;i> a[i][j]; if (j==0 && a[i][j] != -1) dp[i][j] = a[i][j]; } } for (int j=1;j, greater

> que; for (int i=1;i=0 && a[i-1][j] != -1) { int nv = v + a[i-1][j]; if (dp[i-1][j] > nv) { que.push(P(nv, i-1)); dp[i-1][j] = nv; } } if (i+1 nv) { que.push(P(nv, i+1)); dp[i+1][j] = nv; } } } } ll ans = INF; for (int i=0;i