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
//
//  main.cpp
//  ran2
//
//  Created by Wojciech Siwko on 10/12/2021.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> in(n);
    for (int i = 0; i < n; i++) {
        cin >> in[i];
    }
    long long tmed, tmax, max = 0, count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            vector<int> temp(j-i+1);
            for (int k = i; k <= j; k++) {
                temp[k-i] = in[k];
            }
            sort(temp.begin(), temp.end());
            if (temp.size() % 2 == 1) {
                tmed = 2*temp[(temp.size()-1)/2];
            }
            else {
                tmed = temp[(temp.size()/2)-1] + temp[temp.size()/2];
            }
            tmax = tmed + temp.size();
            if (tmax == max) count++;
            else if (tmax > max){max = tmax; count = 1;}
        }
    }
    cout << max << " " << count << endl;
    return 0;
}