#include <iostream> int main(){ int oldest = 2020, curr = 0; int n, k; std::cin >> n >> k; int limit = k < n ? k : n; for (int i = 1; i <= limit; i++) { int moves = i, changer = i - 2; for (int j = 1; j <= i; j++) { std::cin >> curr; if (curr < oldest && moves <= k) oldest = curr; moves = moves + changer; changer = changer - 2; } } std::cout << oldest; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> int main(){ int oldest = 2020, curr = 0; int n, k; std::cin >> n >> k; int limit = k < n ? k : n; for (int i = 1; i <= limit; i++) { int moves = i, changer = i - 2; for (int j = 1; j <= i; j++) { std::cin >> curr; if (curr < oldest && moves <= k) oldest = curr; moves = moves + changer; changer = changer - 2; } } std::cout << oldest; } |