#include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(0); int rows; int bottles; int year; int best_year; cin >> rows >> bottles >> best_year; for (int row = 2; row <= rows && row < bottles + 2; ++row) { for (int col = 1; col <= row; ++col) { cin >> year; if (best_year > year) { int dep = row * (row - 1) / 2; if(col >= 3){ dep -= (col - 1) * (col - 2) / 2; } if(row - col >= 2) { dep -= (row - col) * (row - col - 1) / 2; } if(dep < bottles){ best_year = year; } } } } cout << best_year << endl; 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> using namespace std; int main() { ios_base::sync_with_stdio(0); int rows; int bottles; int year; int best_year; cin >> rows >> bottles >> best_year; for (int row = 2; row <= rows && row < bottles + 2; ++row) { for (int col = 1; col <= row; ++col) { cin >> year; if (best_year > year) { int dep = row * (row - 1) / 2; if(col >= 3){ dep -= (col - 1) * (col - 2) / 2; } if(row - col >= 2) { dep -= (row - col) * (row - col - 1) / 2; } if(dep < bottles){ best_year = year; } } } } cout << best_year << endl; return 0; } |