#include <cstdio> #include <algorithm> using namespace std; const int N = 2e3; const int INF = 1e9 + 1; int n, k, x[N][N], r = INF; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { x[i][0] = x[i][i] = 1 + i; for (int j = 1; j < i; ++j) x[i][j] = 1 + x[i-1][j-1] + x[i-1][j] - x[i-2][j-1]; for (int j = 0; j <= i; ++j) { int a; scanf("%d", &a); if (x[i][j] <= k) r = min(r, a); } } printf("%d\n", r); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <cstdio> #include <algorithm> using namespace std; const int N = 2e3; const int INF = 1e9 + 1; int n, k, x[N][N], r = INF; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { x[i][0] = x[i][i] = 1 + i; for (int j = 1; j < i; ++j) x[i][j] = 1 + x[i-1][j-1] + x[i-1][j] - x[i-2][j-1]; for (int j = 0; j <= i; ++j) { int a; scanf("%d", &a); if (x[i][j] <= k) r = min(r, a); } } printf("%d\n", r); return 0; } |