#include <algorithm> #include <cstdio> #include <vector> using namespace std; int main() { int n, k; scanf("%d%d", &n, &k); vector<vector<int>> d(n); vector<vector<int>> m(n); for(int i = 0; i < n; ++i) { d[i].reserve(i+1); m[i].resize(i+1); for(int j = 0; j <= i; ++j) { int a; scanf("%d", &a); d[i].push_back(a); } } for(int i = 0; i < n; ++i) { m[i].front() = i + 1; m[i].back() = i + 1; } for(int i = 2; i < n; ++i) { for(int j = 1; j < (m[i].size()-1); ++j) { m[i][j] = i + (static_cast<int>(m[i].size()) - i) + m[i-2][j-1]; } } int res = d[0][0]; for(int i = 0; i < n; ++i) { for(int j = 0; j < d[i].size(); ++j) { if(m[i][j] <= k) res = min(res, d[i][j]); } } printf("%d\n", res); }
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 | #include <algorithm> #include <cstdio> #include <vector> using namespace std; int main() { int n, k; scanf("%d%d", &n, &k); vector<vector<int>> d(n); vector<vector<int>> m(n); for(int i = 0; i < n; ++i) { d[i].reserve(i+1); m[i].resize(i+1); for(int j = 0; j <= i; ++j) { int a; scanf("%d", &a); d[i].push_back(a); } } for(int i = 0; i < n; ++i) { m[i].front() = i + 1; m[i].back() = i + 1; } for(int i = 2; i < n; ++i) { for(int j = 1; j < (m[i].size()-1); ++j) { m[i][j] = i + (static_cast<int>(m[i].size()) - i) + m[i-2][j-1]; } } int res = d[0][0]; for(int i = 0; i < n; ++i) { for(int j = 0; j < d[i].size(); ++j) { if(m[i][j] <= k) res = min(res, d[i][j]); } } printf("%d\n", res); } |