#include<iostream> #include<vector> #include<algorithm> using namespace std; const int ene = 2002; int t[ene][ene]; vector< pair<int,int> > v; int main() { int n,k; cin >> n >> k; t[1][1] = 1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= i; j++) { int a; cin >> a; t[i][j] = t[i-1][j]+j; //cout << t[i][j] << "\n"; v.push_back({a,t[i][j]}); } } sort(v.begin(), v.end()); for(int i = 0; i < v.size(); i++) { if(v[i].second <= k) { cout << v[i].first << "\n"; return 0; } } 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 | #include<iostream> #include<vector> #include<algorithm> using namespace std; const int ene = 2002; int t[ene][ene]; vector< pair<int,int> > v; int main() { int n,k; cin >> n >> k; t[1][1] = 1; for(int i = 1; i <= n; i++) { for(int j = 1; j <= i; j++) { int a; cin >> a; t[i][j] = t[i-1][j]+j; //cout << t[i][j] << "\n"; v.push_back({a,t[i][j]}); } } sort(v.begin(), v.end()); for(int i = 0; i < v.size(); i++) { if(v[i].second <= k) { cout << v[i].first << "\n"; return 0; } } return 0; } |