#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int max = 0; int ile = 0; int dlg = 0; int xd; int ans = 0; for (int i = 0; i < n; i++){ for (int j = i; j < n; j++){ vector<int> aa; for (int c = i; c <= j; c++) aa.push_back(a[c]); dlg = j - i + 1; sort(aa.begin(), aa.end()); if (dlg%2){ xd = 2*aa[dlg/2]; } else{ xd = ((aa[dlg/2] + aa[dlg/2 - 1])); } ans = (dlg + xd); if (ans == max) ile++; else if (ans > max){ max = ans; ile = 1; } aa.clear(); } } cout << max << " " << ile << 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 37 38 39 40 | #include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int max = 0; int ile = 0; int dlg = 0; int xd; int ans = 0; for (int i = 0; i < n; i++){ for (int j = i; j < n; j++){ vector<int> aa; for (int c = i; c <= j; c++) aa.push_back(a[c]); dlg = j - i + 1; sort(aa.begin(), aa.end()); if (dlg%2){ xd = 2*aa[dlg/2]; } else{ xd = ((aa[dlg/2] + aa[dlg/2 - 1])); } ans = (dlg + xd); if (ans == max) ile++; else if (ans > max){ max = ans; ile = 1; } aa.clear(); } } cout << max << " " << ile << endl; return 0; } |