#include <iostream>
#include <vector>
//#include <fstream>
//#include <Windows.h>
using namespace std;
vector <int> piramida[2001];
vector <int> butle[2001];
int main()
{
//fstream f;
//f.open("tesst.txt", ios::in);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
int ilosc_butelek;
cin >> n >> k;
ilosc_butelek = n * (n + 1);
ilosc_butelek /= 2;
int t1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i + 1; j++) {
cin >> t1;
piramida[i].push_back(t1);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < i + 1; j++) {
if (i == 0) {
butle[i].push_back(1);
}
else {
if (j == 0) {
butle[i].push_back(butle[i - 1][j] + 1);
}
else if (j == i) {
butle[i].push_back(butle[i - 1][j - 1] + 1);
}
else {
butle[i].push_back(butle[i - 1][j - 1] + butle[i - 1][j] + 1 - butle[i - 2][j - 1]);
}
}
}
}
int max_rok = 4000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i + 1; j++) {
if (piramida[i][j] < max_rok) {
if (butle[i][j] <= k) {
max_rok = piramida[i][j];
}
}
}
}
cout << max_rok;
//system("sleep");
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <iostream> #include <vector> //#include <fstream> //#include <Windows.h> using namespace std; vector <int> piramida[2001]; vector <int> butle[2001]; int main() { //fstream f; //f.open("tesst.txt", ios::in); ios_base::sync_with_stdio(0); cin.tie(0); int n, k; int ilosc_butelek; cin >> n >> k; ilosc_butelek = n * (n + 1); ilosc_butelek /= 2; int t1; for (int i = 0; i < n; i++) { for (int j = 0; j < i + 1; j++) { cin >> t1; piramida[i].push_back(t1); } } for (int i = 0; i < n; i++) { for (int j = 0; j < i + 1; j++) { if (i == 0) { butle[i].push_back(1); } else { if (j == 0) { butle[i].push_back(butle[i - 1][j] + 1); } else if (j == i) { butle[i].push_back(butle[i - 1][j - 1] + 1); } else { butle[i].push_back(butle[i - 1][j - 1] + butle[i - 1][j] + 1 - butle[i - 2][j - 1]); } } } } int max_rok = 4000; for (int i = 0; i < n; i++) { for (int j = 0; j < i + 1; j++) { if (piramida[i][j] < max_rok) { if (butle[i][j] <= k) { max_rok = piramida[i][j]; } } } } cout << max_rok; //system("sleep"); return 0; } |
English