#include <bits/stdc++.h> using namespace std; int n, ans = INT_MAX; long long k; long long pir[2005][2005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; pir[1][1] = 1; for (int i = 2; i <= n; i++) for (int j = 1; j <= i; j++) pir[i][j] = pir[i-1][j] + pir[i-1][j-1] - pir[i-2][j-1] + 1; for (int i = 1; i <= n; i++) for (int j = 1, x; j <= i; j++) { cin >> x; if (pir[i][j] <= k) ans = min(ans, x); } cout << ans << '\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 26 27 28 | #include <bits/stdc++.h> using namespace std; int n, ans = INT_MAX; long long k; long long pir[2005][2005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; pir[1][1] = 1; for (int i = 2; i <= n; i++) for (int j = 1; j <= i; j++) pir[i][j] = pir[i-1][j] + pir[i-1][j-1] - pir[i-2][j-1] + 1; for (int i = 1; i <= n; i++) for (int j = 1, x; j <= i; j++) { cin >> x; if (pir[i][j] <= k) ans = min(ans, x); } cout << ans << '\n'; } |