#include <iostream> #include <queue> using namespace std; #define MAX_LEVEL_SIZE 2010 #define INF 2030 int pyramid[MAX_LEVEL_SIZE][MAX_LEVEL_SIZE]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, min_year = INF, a; cin >> n >> k; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { cin >> a; if (j == 0 || j == i) { pyramid[i][j] = i + 1; } else { pyramid[i][j] = pyramid[i - 1][j - 1] + pyramid[i - 1][j] - pyramid[i - 2][j - 1] + 1; } if (pyramid[i][j] <= k) { min_year = min(min_year, a); } } } cout << min_year; }
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 38 39 40 41 42 43 | #include <iostream> #include <queue> using namespace std; #define MAX_LEVEL_SIZE 2010 #define INF 2030 int pyramid[MAX_LEVEL_SIZE][MAX_LEVEL_SIZE]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, min_year = INF, a; cin >> n >> k; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { cin >> a; if (j == 0 || j == i) { pyramid[i][j] = i + 1; } else { pyramid[i][j] = pyramid[i - 1][j - 1] + pyramid[i - 1][j] - pyramid[i - 2][j - 1] + 1; } if (pyramid[i][j] <= k) { min_year = min(min_year, a); } } } cout << min_year; } |