#include <iostream> #include <vector> #include <stack> #include <unordered_set> #include <set> #include <map> #include <algorithm> using namespace std; pair<int,int> getNextMinBarrel(vector<vector< pair<int, bool> >>& pyramid) { int minYear = 3000; //ai <=2019 anyway pair<int,int> minBarrelIndex; for(int i = 0; i < pyramid.size(); ++i) { for(int j = 0; j < i + 1; ++j) { if(pyramid[i][j].second == true) continue; if(pyramid[i][j].first < minYear) { minYear = pyramid[i][j].first; minBarrelIndex = make_pair(i,j); } } } return minBarrelIndex; } void fillColumn(int col, int tab[200][200]) { tab[col][col] = col; for(int row = col+1; row < 200; ++row) { tab[row][col] = tab[row-1][col] +(col+1); } } int main() { int heightOfPyramid = 0; cin >> heightOfPyramid; int numberOfNeededBarrels = 0; cin >> numberOfNeededBarrels; vector<pair<int,pair<int,int>>> sortedBarrels; for(int i = 0; i < heightOfPyramid; ++i) { for(int j = 0; j < i + 1; ++j) { int year = 0; cin >> year; sortedBarrels.push_back(make_pair(year, make_pair(i,j))); } } sort(sortedBarrels.begin(), sortedBarrels.end()); int tab[200][200]; for(int i = 0; i < 200; ++i) { for(int j = 0; j < 200; ++j) { tab[i][j] = 0; } } for(int col = 0; col < 200; ++col) { fillColumn(col, tab); } for(auto i : sortedBarrels) { if(tab[i.second.first][i.second.second] + 1 <= numberOfNeededBarrels) { cout << i.first << 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | #include <iostream> #include <vector> #include <stack> #include <unordered_set> #include <set> #include <map> #include <algorithm> using namespace std; pair<int,int> getNextMinBarrel(vector<vector< pair<int, bool> >>& pyramid) { int minYear = 3000; //ai <=2019 anyway pair<int,int> minBarrelIndex; for(int i = 0; i < pyramid.size(); ++i) { for(int j = 0; j < i + 1; ++j) { if(pyramid[i][j].second == true) continue; if(pyramid[i][j].first < minYear) { minYear = pyramid[i][j].first; minBarrelIndex = make_pair(i,j); } } } return minBarrelIndex; } void fillColumn(int col, int tab[200][200]) { tab[col][col] = col; for(int row = col+1; row < 200; ++row) { tab[row][col] = tab[row-1][col] +(col+1); } } int main() { int heightOfPyramid = 0; cin >> heightOfPyramid; int numberOfNeededBarrels = 0; cin >> numberOfNeededBarrels; vector<pair<int,pair<int,int>>> sortedBarrels; for(int i = 0; i < heightOfPyramid; ++i) { for(int j = 0; j < i + 1; ++j) { int year = 0; cin >> year; sortedBarrels.push_back(make_pair(year, make_pair(i,j))); } } sort(sortedBarrels.begin(), sortedBarrels.end()); int tab[200][200]; for(int i = 0; i < 200; ++i) { for(int j = 0; j < 200; ++j) { tab[i][j] = 0; } } for(int col = 0; col < 200; ++col) { fillColumn(col, tab); } for(auto i : sortedBarrels) { if(tab[i.second.first][i.second.second] + 1 <= numberOfNeededBarrels) { cout << i.first << endl; break; } } return 0; } |