#include <bits/stdc++.h> using namespace std; #define N 2000 int lata[N][N]; int kroki[N][N]; int main() { int n, k; scanf("%d %d", &n, &k); int mn = INT_MAX; int j = 1; for (int i = 0; i < n; i++) { for (int l = 0; l < j; l++) { scanf("%d", &(lata[i][l])); } j++; } j = 2; kroki[0][0] = 1; for (int i = 1; i < n; i++) { for (int l = 0; l < j; l++) { if (l <= j/2) { kroki[i][l] = kroki[i - 1][l] + l + 1; } else { kroki[i][l] = kroki[i][j - l - 1]; } } j++; } j = 1; for (int i = 0; i < n; i++) { for (int l = 0; l < j; l++) { if (kroki[i][l] <= k && lata[i][l] != 0) { mn = min(mn, lata[i][l]); } } j++; } printf("%d", mn); return 0; } /* 5 7 1999 2019 2010 850 1500 1600 900 900 710 900 1000 800 600 800 1000 */
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <bits/stdc++.h> using namespace std; #define N 2000 int lata[N][N]; int kroki[N][N]; int main() { int n, k; scanf("%d %d", &n, &k); int mn = INT_MAX; int j = 1; for (int i = 0; i < n; i++) { for (int l = 0; l < j; l++) { scanf("%d", &(lata[i][l])); } j++; } j = 2; kroki[0][0] = 1; for (int i = 1; i < n; i++) { for (int l = 0; l < j; l++) { if (l <= j/2) { kroki[i][l] = kroki[i - 1][l] + l + 1; } else { kroki[i][l] = kroki[i][j - l - 1]; } } j++; } j = 1; for (int i = 0; i < n; i++) { for (int l = 0; l < j; l++) { if (kroki[i][l] <= k && lata[i][l] != 0) { mn = min(mn, lata[i][l]); } } j++; } printf("%d", mn); return 0; } /* 5 7 1999 2019 2010 850 1500 1600 900 900 710 900 1000 800 600 800 1000 */ |