#include<iostream>
#include<vector>
using namespace std;
vector<int> tab[2100000];
vector<int> d[2100000];
int main(){
int n, k;
cin >> n >> k;
int licz = 1;
for(int i = 0; i < n; i++){
for(int j = 0; j < licz; j++){
int y;
cin >> y;
tab[i].push_back(y);
}
licz++;
}
licz = 2;
d[0].push_back(1);
for(int i = 1; i < n; i++){
for(int j = 0; j < licz; j++){
if(j == 0){
d[i].push_back(d[i-1][0] + 1);
continue;
}
if(j == tab[i].size()-1){
d[i].push_back(d[i-1][d[i-1].size()-1] + 1);
continue;
}
d[i].push_back(d[i-1][j-1] + d[i-1][j] - d[i-2][j-1] + 1);
}
licz++;
}
int wyn = 20000;
licz = 1;
for(int i = 0; i < n; i++){
for(int j = 0; j < licz; j++){
if(d[i][j] <= k){
wyn = min(wyn, tab[i][j]);
}
}
licz++;
}
cout << wyn;
}
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 | #include<iostream> #include<vector> using namespace std; vector<int> tab[2100000]; vector<int> d[2100000]; int main(){ int n, k; cin >> n >> k; int licz = 1; for(int i = 0; i < n; i++){ for(int j = 0; j < licz; j++){ int y; cin >> y; tab[i].push_back(y); } licz++; } licz = 2; d[0].push_back(1); for(int i = 1; i < n; i++){ for(int j = 0; j < licz; j++){ if(j == 0){ d[i].push_back(d[i-1][0] + 1); continue; } if(j == tab[i].size()-1){ d[i].push_back(d[i-1][d[i-1].size()-1] + 1); continue; } d[i].push_back(d[i-1][j-1] + d[i-1][j] - d[i-2][j-1] + 1); } licz++; } int wyn = 20000; licz = 1; for(int i = 0; i < n; i++){ for(int j = 0; j < licz; j++){ if(d[i][j] <= k){ wyn = min(wyn, tab[i][j]); } } licz++; } cout << wyn; } |
English