#include <cstdio> int n, k, best, year, min_k; int pyramid[2002][2002]; int main() { scanf("%d %d", &n, &k); best = 2019; for(int r=1; r <= n; ++r) { for(int m=1; m <= r; ++m) { scanf("%d", &year); min_k = pyramid[r-1][m-1] + r - m + 1; pyramid[r][m] = min_k; if(min_k <= k && year < best) best = year; } } printf("%d\n", best); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <cstdio> int n, k, best, year, min_k; int pyramid[2002][2002]; int main() { scanf("%d %d", &n, &k); best = 2019; for(int r=1; r <= n; ++r) { for(int m=1; m <= r; ++m) { scanf("%d", &year); min_k = pyramid[r-1][m-1] + r - m + 1; pyramid[r][m] = min_k; if(min_k <= k && year < best) best = year; } } printf("%d\n", best); } |