#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct butkoord
{
int rocznik;
int x;
int y;
};
bool compare_buts(const butkoord& a,const butkoord& b)
{
return a.rocznik<b.rocznik;
}
int main()
{
int n,k;
cin>>n>>k;
vector< butkoord > wszystkie;
vector< vector<int> > butelki;
for(int x=1;x<=n;x++)
{
vector< int > rzad;
for(int y=1;y<=x;y++)
{
int butelka;
cin>>butelka;
butkoord bk;
bk.rocznik=butelka;
bk.x=x;
bk.y=y;
rzad.push_back(butelka);
wszystkie.push_back(bk);
}
butelki.push_back(rzad);
}
sort(&wszystkie[0],&wszystkie[wszystkie.size()], compare_buts);
for(int i=0;i<wszystkie.size();i++)
{
butkoord najstarsza=wszystkie[i];
int droga=(najstarsza.x-(najstarsza.y-1))*najstarsza.y;
if(droga<=k)
{
cout<<najstarsza.rocznik<<endl;
break;
}
}
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; struct butkoord { int rocznik; int x; int y; }; bool compare_buts(const butkoord& a,const butkoord& b) { return a.rocznik<b.rocznik; } int main() { int n,k; cin>>n>>k; vector< butkoord > wszystkie; vector< vector<int> > butelki; for(int x=1;x<=n;x++) { vector< int > rzad; for(int y=1;y<=x;y++) { int butelka; cin>>butelka; butkoord bk; bk.rocznik=butelka; bk.x=x; bk.y=y; rzad.push_back(butelka); wszystkie.push_back(bk); } butelki.push_back(rzad); } sort(&wszystkie[0],&wszystkie[wszystkie.size()], compare_buts); for(int i=0;i<wszystkie.size();i++) { butkoord najstarsza=wszystkie[i]; int droga=(najstarsza.x-(najstarsza.y-1))*najstarsza.y; if(droga<=k) { cout<<najstarsza.rocznik<<endl; break; } } return 0; } |
English