#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 5;
int t[MAX_N];
int res = 0;
int res_cnt = 0;
int main() {
cin.tie(0); ios_base::sync_with_stdio(false);
int n; cin >> n;
for(int i = 0; i < n; i++) cin >> t[i];
for(int i = 0; i < n; i++) {
for(int j = i; j < n; j++) {
int max_a = 0, max_b = 0;
vector<int> sorted;
sorted.resize(j - i + 1);
for(int k = i; k <= j; k++) {
sorted[k-i] = t[k];
}
sort(sorted.begin(), sorted.end());
int temp_res;
if((j - i + 1) % 2 == 0) {
temp_res = sorted[sorted.size()/2] + sorted[sorted.size()/2-1] + (j - i + 1);
}
else {
temp_res = 2 * sorted[sorted.size()/2] + (j - i + 1);
}
if(temp_res == res) {
res_cnt++;
}
else if(temp_res > res) {
res = temp_res;
res_cnt = 1;
}
}
}
cout << res << ' ' << res_cnt;
}
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 <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 5; int t[MAX_N]; int res = 0; int res_cnt = 0; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; for(int i = 0; i < n; i++) cin >> t[i]; for(int i = 0; i < n; i++) { for(int j = i; j < n; j++) { int max_a = 0, max_b = 0; vector<int> sorted; sorted.resize(j - i + 1); for(int k = i; k <= j; k++) { sorted[k-i] = t[k]; } sort(sorted.begin(), sorted.end()); int temp_res; if((j - i + 1) % 2 == 0) { temp_res = sorted[sorted.size()/2] + sorted[sorted.size()/2-1] + (j - i + 1); } else { temp_res = 2 * sorted[sorted.size()/2] + (j - i + 1); } if(temp_res == res) { res_cnt++; } else if(temp_res > res) { res = temp_res; res_cnt = 1; } } } cout << res << ' ' << res_cnt; } |
English