#include <iostream> using namespace std; int how_many_to_remove(const int& N, const int& w, const int& k) { return N * (N + 1) / 2 - (k * (k + 1) / 2 + (w - k - 1)*(w - k)/2 + (2*(w + 1) +(N - w - 1))*(N - w)/2); } int main() { int n, k,a; a = 0; cin >> n; cin >> k; int mini = 99999; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { cin >> a; if (how_many_to_remove(n, i, j) <= k && a<mini)mini = a; } } cout << mini; 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> using namespace std; int how_many_to_remove(const int& N, const int& w, const int& k) { return N * (N + 1) / 2 - (k * (k + 1) / 2 + (w - k - 1)*(w - k)/2 + (2*(w + 1) +(N - w - 1))*(N - w)/2); } int main() { int n, k,a; a = 0; cin >> n; cin >> k; int mini = 99999; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { cin >> a; if (how_many_to_remove(n, i, j) <= k && a<mini)mini = a; } } cout << mini; return 0; } |