#include <iostream> using namespace std; int main() { int n, k, bottlesInRow = 1, currentBottle, bestBottle = 2019; cin >> n >> k; for (int j = 0; j < n; ++j) { for (int i = 1; i <= bottlesInRow; ++i) { cin >> currentBottle; if (currentBottle < bestBottle) { if ((bottlesInRow - i + 1) * (bottlesInRow - (bottlesInRow - i)) <= k) bestBottle = currentBottle; } } ++bottlesInRow; } cout << bestBottle << endl; 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 24 25 26 27 | #include <iostream> using namespace std; int main() { int n, k, bottlesInRow = 1, currentBottle, bestBottle = 2019; cin >> n >> k; for (int j = 0; j < n; ++j) { for (int i = 1; i <= bottlesInRow; ++i) { cin >> currentBottle; if (currentBottle < bestBottle) { if ((bottlesInRow - i + 1) * (bottlesInRow - (bottlesInRow - i)) <= k) bestBottle = currentBottle; } } ++bottlesInRow; } cout << bestBottle << endl; return 0; } |