#include <iostream> using namespace std; int piramida(int n) { return (n * (n+1))/2; } int main() { int n, k; cin >> n >> k; int best = 20190; for(int i = 1; i <= n; i++) { for(int ii = 1; ii <= i; ii++) { int val; cin >> val; if(val < best) { int count = piramida(i) - piramida(ii - 1) - piramida(i - ii); if(count <= k) best = val; } } } cout << best << endl; }
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 | #include <iostream> using namespace std; int piramida(int n) { return (n * (n+1))/2; } int main() { int n, k; cin >> n >> k; int best = 20190; for(int i = 1; i <= n; i++) { for(int ii = 1; ii <= i; ii++) { int val; cin >> val; if(val < best) { int count = piramida(i) - piramida(ii - 1) - piramida(i - ii); if(count <= k) best = val; } } } cout << best << endl; } |