#include <iostream> #include <vector> using namespace std; int triangle(int x) { return x*(x+1)/2; } int minimal_thrapese(int x, int y) { int left_len = y-1; int right_len = x-y; return triangle(x) - triangle(left_len) - triangle(right_len); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int least_val = 1e9; for (int i = 0; i < k; ++i) { for (int j = 0; j < i+1; ++j) { int wino; cin >> wino; if (wino < least_val and minimal_thrapese(i+1, j+1) <= k) { least_val = wino; } } } cout << least_val << "\n"; }
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 | #include <iostream> #include <vector> using namespace std; int triangle(int x) { return x*(x+1)/2; } int minimal_thrapese(int x, int y) { int left_len = y-1; int right_len = x-y; return triangle(x) - triangle(left_len) - triangle(right_len); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int least_val = 1e9; for (int i = 0; i < k; ++i) { for (int j = 0; j < i+1; ++j) { int wino; cin >> wino; if (wino < least_val and minimal_thrapese(i+1, j+1) <= k) { least_val = wino; } } } cout << least_val << "\n"; } |