#include <iostream> #include <cmath> using namespace std; int count2height(int count) { return (int)((sqrt(8 * (double)count + 1) - 1) / 2); } int height2count(int height) { return height * (height + 1) / 2; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int h1, h2; int hk = count2height(k); int maxheight = -1; for (int i = 1; i < hk; i++) { h1 = i; h2 = count2height(k - height2count(h1)); if (h1 + h2 > maxheight) maxheight = h1 + h2; } short int rowmin, x, min = 2020; for (int i = 1; i <= n; i++) { rowmin = 2020; for (int j = 1; j <= i; j++) { cin >> x; if (x < rowmin) rowmin = x; } if (i <= maxheight && rowmin < min) min = rowmin; } cout<< min; 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 <iostream> #include <cmath> using namespace std; int count2height(int count) { return (int)((sqrt(8 * (double)count + 1) - 1) / 2); } int height2count(int height) { return height * (height + 1) / 2; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int h1, h2; int hk = count2height(k); int maxheight = -1; for (int i = 1; i < hk; i++) { h1 = i; h2 = count2height(k - height2count(h1)); if (h1 + h2 > maxheight) maxheight = h1 + h2; } short int rowmin, x, min = 2020; for (int i = 1; i <= n; i++) { rowmin = 2020; for (int j = 1; j <= i; j++) { cin >> x; if (x < rowmin) rowmin = x; } if (i <= maxheight && rowmin < min) min = rowmin; } cout<< min; return 0; } |