#include<cstdio> #include<vector> #include<limits> #include<algorithm> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); vector<vector<int>> b(n); for (int i = 0; i < n; ++i) { b[i].resize(i + 1); for (int j = 0; j <= i; ++j) { scanf("%d", &b[i][j]); } } int best = numeric_limits<int>::max(); int size = 0; for (int i = 0; i < n && i < k; ++i) { int steps = i + 1; if (steps <= k) best = min(best, b[i][0]); for (int j = 1; j <= i; ++j) { steps += i - j - (j - 1); if (steps <= k) best = min(best, b[i][j]); } } printf("%d\n", best); 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 | #include<cstdio> #include<vector> #include<limits> #include<algorithm> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); vector<vector<int>> b(n); for (int i = 0; i < n; ++i) { b[i].resize(i + 1); for (int j = 0; j <= i; ++j) { scanf("%d", &b[i][j]); } } int best = numeric_limits<int>::max(); int size = 0; for (int i = 0; i < n && i < k; ++i) { int steps = i + 1; if (steps <= k) best = min(best, b[i][0]); for (int j = 1; j <= i; ++j) { steps += i - j - (j - 1); if (steps <= k) best = min(best, b[i][j]); } } printf("%d\n", best); return 0; } |