#include <iostream> #include <algorithm> using namespace std; int fun(int i, int j) { return(i*j + i - j * j + 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k, r, min = INT32_MAX; cin >> n >> k; int minp = std::min(n, k); for (int i = 0; i < minp; ++i) { for (int j = 0; j < i + 1; ++j) { cin >> r; if (fun(i, j) <= k) { if (r < min) { min = r; } } } } cout << min; 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 28 29 | #include <iostream> #include <algorithm> using namespace std; int fun(int i, int j) { return(i*j + i - j * j + 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k, r, min = INT32_MAX; cin >> n >> k; int minp = std::min(n, k); for (int i = 0; i < minp; ++i) { for (int j = 0; j < i + 1; ++j) { cin >> r; if (fun(i, j) <= k) { if (r < min) { min = r; } } } } cout << min; return 0; } |