#include <bits/stdc++.h> using namespace std; int n, a[1000002], wyn, ile, med, b[1000002]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); b[i] = a[i]; } wyn = 2 * n + 1; ile = 1; for (int l = 0; l < n; ++l) { for (int r = l + 1; r < n; ++r) { sort(b + l, b + r + 1); if ((r - l + 1) % 2 == 0) { // cout << l + (r - l + 1) / 2; med = b[l + (r - l + 1) / 2] + b[l + (r - l + 1) / 2 - 1]; } else med = b[l + (r - l + 1) / 2] * 2; if (med + r - l + 1 == wyn) ile++; else if (med + (r - l + 1) > wyn) { wyn = med + r - l + 1; ile = 1; } /* cout << l << " " << r << " " << med << endl; for (int j = l; j <= r; ++j) cout << b[j] << " "; cout << endl;*/ for (int j = l; j <= r; ++j) b[j] = a[j]; // cout << endl; } } printf("%d %d", wyn, ile); }
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 | #include <bits/stdc++.h> using namespace std; int n, a[1000002], wyn, ile, med, b[1000002]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); b[i] = a[i]; } wyn = 2 * n + 1; ile = 1; for (int l = 0; l < n; ++l) { for (int r = l + 1; r < n; ++r) { sort(b + l, b + r + 1); if ((r - l + 1) % 2 == 0) { // cout << l + (r - l + 1) / 2; med = b[l + (r - l + 1) / 2] + b[l + (r - l + 1) / 2 - 1]; } else med = b[l + (r - l + 1) / 2] * 2; if (med + r - l + 1 == wyn) ile++; else if (med + (r - l + 1) > wyn) { wyn = med + r - l + 1; ile = 1; } /* cout << l << " " << r << " " << med << endl; for (int j = l; j <= r; ++j) cout << b[j] << " "; cout << endl;*/ for (int j = l; j <= r; ++j) b[j] = a[j]; // cout << endl; } } printf("%d %d", wyn, ile); } |