//嘘解法が通らないか確認 #include #include using namespace std; using ll = long long; int main () { int N, M, K, T; cin >> N >> M >> K >> T; assert(1 <= N && N <= 80); assert(1 <= M && M <= 80); assert(0 <= K && K <= N * M - 2); assert(1 <= T <= (int)1e9); ll C[88][88]; ll D[88][88]; for (int i = 0; i < N; i ++) { for (int j = 0; j < M; j ++) { C[i][j] = D[i][j] = 0; } } for (int i = 0; i < K; i ++) { int a, b; cin >> a >> b; assert(1 <= a && a <= N); assert(1 <= b && b <= M); assert(2 < a + b && a + b < N + M); a --; b --; assert(C[a][b] == 0); cin >> C[a][b] >> D[a][b]; } if (T > N + M - 1) { cout << "0" << endl; return 0; } ll dp[406][88][88]; ll INF = (ll)1e18; for (int i = 0; i <= (N + M) * 2 - 1; i ++) { for (int j = 0; j < N; j ++) { for (int k = 0; k < M; k ++) { dp[i][j][k] = INF; } } } for (int i = N + M - 1; i <= (N + M) * 2 - 1; i ++) { dp[0][0][i] = 0; } for (int i = 0; i < N; i ++) { for (int j = 0; j < M; j ++) { if (i + j == 0) { continue; } for (int k = (N + M) * 2 - 1; k >= 0; k --) { if (k > 0) { if (i > 0) { dp[k][i][j] = min(dp[k][i][j], dp[k - 1][i - 1][j]); } if (j > 0) { dp[k][i][j] = min(dp[k][i][j], dp[k - 1][i][j - 1]); } } if (C[i][j] > 1) { int kj = max(0ll, k - C[i][j] + 1); dp[kj][i][j] = min(dp[kj][i][j], dp[k][i][j] + D[i][j]); } } } } ll ans = INF; for (int i = 0; i <= T + N + M - 1; i ++) { ans = min(ans, dp[i][N - 1][M - 1]); } cout << ans << endl; }