#include <iostream> #include <algorithm> #include <vector> using namespace std; using ll = long long; int ans[10003][10003]{}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n{}; cin >> n; int aa{}; vector<int> a{}; for (int i = 0; i < n; i++) { cin >> aa; a.push_back(aa); } int ma{}; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { vector<int> b{}; for (int k = i; k <= j; k++) { b.push_back(a[k]); } sort(b.begin(), b.end()); int med{}; int s = b.size(); if (s%2 == 1) med = 2*b[s/2]; else med = b[s/2-1]+b[s/2]; // cout << i << " " << j << " " << s << " " << med << "\n"; ans[i][j] = s+med; ma = max(ma, ans[i][j]); } } int aaa{}; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (ans[i][j] == ma) aaa++; } } cout << ma << " " << aaa << "\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 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <iostream> #include <algorithm> #include <vector> using namespace std; using ll = long long; int ans[10003][10003]{}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n{}; cin >> n; int aa{}; vector<int> a{}; for (int i = 0; i < n; i++) { cin >> aa; a.push_back(aa); } int ma{}; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { vector<int> b{}; for (int k = i; k <= j; k++) { b.push_back(a[k]); } sort(b.begin(), b.end()); int med{}; int s = b.size(); if (s%2 == 1) med = 2*b[s/2]; else med = b[s/2-1]+b[s/2]; // cout << i << " " << j << " " << s << " " << med << "\n"; ans[i][j] = s+med; ma = max(ma, ans[i][j]); } } int aaa{}; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (ans[i][j] == ma) aaa++; } } cout << ma << " " << aaa << "\n"; } |