#include <iostream> int W[2001][3]; int main() { std::ios_base::sync_with_stdio(0); int n, k; std::cin >> n >> k; int result = 2020; for (int i=1;i<=n;++i) { for (int j=1;j<=i;++j) { int a; std::cin >> a; W[j][i%3] = 1 + W[j-1][(i+2)%3] + W[j][(i+2)%3] - W[j-1][(i+1)%3]; if (W[j][i%3] <= k) result = std::min(result, a); } } std::cout << result << std::endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> int W[2001][3]; int main() { std::ios_base::sync_with_stdio(0); int n, k; std::cin >> n >> k; int result = 2020; for (int i=1;i<=n;++i) { for (int j=1;j<=i;++j) { int a; std::cin >> a; W[j][i%3] = 1 + W[j-1][(i+2)%3] + W[j][(i+2)%3] - W[j-1][(i+1)%3]; if (W[j][i%3] <= k) result = std::min(result, a); } } std::cout << result << std::endl; return 0; } |