#include <algorithm> #include <cstdio> int main() { int n, k, year; int answer; scanf("%d%d", &n, &k); scanf("%d", &answer); for (int i = 2; i <= n; i++) { int current = i; int change = i; for (int j = 1; j <= i; j++) { scanf("%d", &year); if (current <= k) { answer = std::min(answer, year); } change -= 2; current += change; } } printf("%d", answer); 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 | #include <algorithm> #include <cstdio> int main() { int n, k, year; int answer; scanf("%d%d", &n, &k); scanf("%d", &answer); for (int i = 2; i <= n; i++) { int current = i; int change = i; for (int j = 1; j <= i; j++) { scanf("%d", &year); if (current <= k) { answer = std::min(answer, year); } change -= 2; current += change; } } printf("%d", answer); return 0; } |