#include <iostream> #include <vector> using namespace std; int main() { short int n, k, buffer, king, bottle_count; cin >> n >> k; vector<short int> wine_cellar; for(int i=1; i<=n; i++) { int j=0; while(j<i) { cin >> buffer; if(i==1) { king = buffer; break; } wine_cellar.push_back(buffer); bottle_count++; if(wine_cellar[j]<king) king = wine_cellar[j]; j++; } wine_cellar.clear(); if(bottle_count>=k) { cout << king; 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 | #include <iostream> #include <vector> using namespace std; int main() { short int n, k, buffer, king, bottle_count; cin >> n >> k; vector<short int> wine_cellar; for(int i=1; i<=n; i++) { int j=0; while(j<i) { cin >> buffer; if(i==1) { king = buffer; break; } wine_cellar.push_back(buffer); bottle_count++; if(wine_cellar[j]<king) king = wine_cellar[j]; j++; } wine_cellar.clear(); if(bottle_count>=k) { cout << king; return 0; } } } |