#include <iostream> #include <cstdio> #include <vector> int main() { std::ios_base::sync_with_stdio(false); int n, k, c, res = 2020; scanf("%d %d", &n, &k); std::vector<int> lel1, lel2; for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { int t = lel1[j - 1] + j; scanf("%d", &c); if (t <= k && res > c) { res = c; } lel2.push_back(t); } scanf("%d", &c); if (i <= k && res > c) { res = c; } lel2.push_back(i); lel1.clear(); for (int j = 0; j < lel2.size(); j++) lel1.push_back(lel2[j]); lel2.clear(); } 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 | #include <iostream> #include <cstdio> #include <vector> int main() { std::ios_base::sync_with_stdio(false); int n, k, c, res = 2020; scanf("%d %d", &n, &k); std::vector<int> lel1, lel2; for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { int t = lel1[j - 1] + j; scanf("%d", &c); if (t <= k && res > c) { res = c; } lel2.push_back(t); } scanf("%d", &c); if (i <= k && res > c) { res = c; } lel2.push_back(i); lel1.clear(); for (int j = 0; j < lel2.size(); j++) lel1.push_back(lel2[j]); lel2.clear(); } printf("%d\n", res); } |