#include <iostream> #include <cstdio> using namespace std; int tab[2000][2000]; int get(int x, int y) { if (x < 0 || y < 0 || x >= 2000 || y >= 2000) return 0; else return tab[x][y]; } int main() { int n, k, x; int answer = 2019; scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { for (int j = 0; j <= i; ++j) { scanf("%d", &x); tab[i][j] = get(i-1, j-1) + get(i-1, j) - get(i-2, j-1) + 1; if (tab[i][j] <= k) answer = min(answer, x); } } printf("%d", answer); }
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 | #include <iostream> #include <cstdio> using namespace std; int tab[2000][2000]; int get(int x, int y) { if (x < 0 || y < 0 || x >= 2000 || y >= 2000) return 0; else return tab[x][y]; } int main() { int n, k, x; int answer = 2019; scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { for (int j = 0; j <= i; ++j) { scanf("%d", &x); tab[i][j] = get(i-1, j-1) + get(i-1, j) - get(i-2, j-1) + 1; if (tab[i][j] <= k) answer = min(answer, x); } } printf("%d", answer); } |