#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int wejscie[n+1][n+1], ile_wyjac[n+1][n+1]; for (int i = 0; i <= n; i++) for (int j =0; j<=n; j++) ile_wyjac[i][j]=0; for (int i = 1; i <= n; i++) for (int j = 1; j < i + 1; j++){ cin >> wejscie[i][j]; if (j == 1) ile_wyjac[i][j]= i; else ile_wyjac[i][j] = ile_wyjac[i-1][j-1] + ile_wyjac[i-1][j] - ile_wyjac[i-2][j-1] + 1; } int wynik = 2020; for (int i = 1; i <= n; i++) for (int j =1; j < i + 1; j++){ if (ile_wyjac[i][j]<= k){ wynik = min(wynik, wejscie[i][j]); } } cout << wynik << "\n"; /* for (int i = 1; i <= n; i++){ for (int j =1; j < i + 1; j++) cout << ile_wyjac[i][j] << " "; cout << "\n"; } */ 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 30 31 32 33 34 35 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int wejscie[n+1][n+1], ile_wyjac[n+1][n+1]; for (int i = 0; i <= n; i++) for (int j =0; j<=n; j++) ile_wyjac[i][j]=0; for (int i = 1; i <= n; i++) for (int j = 1; j < i + 1; j++){ cin >> wejscie[i][j]; if (j == 1) ile_wyjac[i][j]= i; else ile_wyjac[i][j] = ile_wyjac[i-1][j-1] + ile_wyjac[i-1][j] - ile_wyjac[i-2][j-1] + 1; } int wynik = 2020; for (int i = 1; i <= n; i++) for (int j =1; j < i + 1; j++){ if (ile_wyjac[i][j]<= k){ wynik = min(wynik, wejscie[i][j]); } } cout << wynik << "\n"; /* for (int i = 1; i <= n; i++){ for (int j =1; j < i + 1; j++) cout << ile_wyjac[i][j] << " "; cout << "\n"; } */ return 0; } |