#include "bits/stdc++.h" using namespace std; int tab[2007][2007], dp[2007][2007]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; for (int i=1; i<=n; i++) { dp[i][1] = dp[i][i] = i; for (int j=2; j<i; j++) { dp[i][j] = (dp[i-1][j-1] + dp[i-1][j] - dp[i-2][j-1] + 1); } } int res = 2020; for (int i=1; i<=n; i++) { for (int j=1; j<=i; j++) { cin >> tab[i][j]; if (dp[i][j] <= k) res = min(res, tab[i][j]); } } cout << res << "\n"; }
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 | #include "bits/stdc++.h" using namespace std; int tab[2007][2007], dp[2007][2007]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; for (int i=1; i<=n; i++) { dp[i][1] = dp[i][i] = i; for (int j=2; j<i; j++) { dp[i][j] = (dp[i-1][j-1] + dp[i-1][j] - dp[i-2][j-1] + 1); } } int res = 2020; for (int i=1; i<=n; i++) { for (int j=1; j<=i; j++) { cin >> tab[i][j]; if (dp[i][j] <= k) res = min(res, tab[i][j]); } } cout << res << "\n"; } |