#include <bits/stdc++.h> using namespace std; const int N = 2000 + 5; int wina[N][N]; int ile[N][N]; void solve(int n, int k) { int res = wina[1][1]; ile[1][1] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { ile[i][j] = 1 + ile[i - 1][j - 1] + ile[i - 1][j] - ile[i - 2][j - 1]; if (ile[i][j] <= k) { res = min(res, wina[i][j]); } } } cout << res << "\n"; } int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { cin >> wina[i][j]; } } solve(n, k); }
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 29 30 31 32 33 34 35 36 37 | #include <bits/stdc++.h> using namespace std; const int N = 2000 + 5; int wina[N][N]; int ile[N][N]; void solve(int n, int k) { int res = wina[1][1]; ile[1][1] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { ile[i][j] = 1 + ile[i - 1][j - 1] + ile[i - 1][j] - ile[i - 2][j - 1]; if (ile[i][j] <= k) { res = min(res, wina[i][j]); } } } cout << res << "\n"; } int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { cin >> wina[i][j]; } } solve(n, k); } |