#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, k, a[2100][2100]; ll dp[2100][2100]; const ll MAX = 1e18; int main(int argc, char *argv[]){ cin >> n >> k; int ans = 1e9; for (int i = 1; i <= n; i++){ for (int j = 1; j <= i; j++){ cin >> a[i][j]; dp[i][j] = dp[i-1][j] + dp[i-1][j-1]+1; dp[i][j] = min(dp[i][j], MAX); if (dp[i][j] != MAX && i > 1 && j > 1) dp[i][j] -= dp[i-2][j-1]; if (dp[i][j] <= k) ans = min(ans, a[i][j]); } } cout << ans; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <bits/stdc++.h> using namespace std; typedef long long ll; int n, k, a[2100][2100]; ll dp[2100][2100]; const ll MAX = 1e18; int main(int argc, char *argv[]){ cin >> n >> k; int ans = 1e9; for (int i = 1; i <= n; i++){ for (int j = 1; j <= i; j++){ cin >> a[i][j]; dp[i][j] = dp[i-1][j] + dp[i-1][j-1]+1; dp[i][j] = min(dp[i][j], MAX); if (dp[i][j] != MAX && i > 1 && j > 1) dp[i][j] -= dp[i-2][j-1]; if (dp[i][j] <= k) ans = min(ans, a[i][j]); } } cout << ans; } |