#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; int n, k; int pyr[MAXN][MAXN]; void read() { scanf("%d%d", &n, &k); for (int lvl = 0; lvl < n; lvl++) { for (int bot = 0; bot <= lvl; bot++) { scanf("%d", &pyr[lvl][bot]); } } } int cost(int lvl, int bot) { return (bot + 1) * (lvl - bot + 1); } int solve() { int result = pyr[0][0]; for (int lvl = 1; lvl < n; lvl++) { for (int bot = 0; bot <= lvl; bot++) { if (cost(lvl, bot) <= k) { result = min(result, pyr[lvl][bot]); } } } return result; } int main() { read(); printf("%d\n", solve()); 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <bits/stdc++.h> using namespace std; const int MAXN = 2005; int n, k; int pyr[MAXN][MAXN]; void read() { scanf("%d%d", &n, &k); for (int lvl = 0; lvl < n; lvl++) { for (int bot = 0; bot <= lvl; bot++) { scanf("%d", &pyr[lvl][bot]); } } } int cost(int lvl, int bot) { return (bot + 1) * (lvl - bot + 1); } int solve() { int result = pyr[0][0]; for (int lvl = 1; lvl < n; lvl++) { for (int bot = 0; bot <= lvl; bot++) { if (cost(lvl, bot) <= k) { result = min(result, pyr[lvl][bot]); } } } return result; } int main() { read(); printf("%d\n", solve()); return 0; } |