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
47
48
49
50
51
52
53
/// THE GAME
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int wyliczMediane (const int a, const int b, const vector <int> &V) {
    // cerr << "Licze mediane (" << a << "," << b << "): ";

    vector <int> bruh;
    for (int i=a;i<=b;i++)
        bruh.push_back(V[i]);
    sort(bruh.begin(), bruh.end());

    if ((b-a+1)%2 == 0)
        return (bruh[(b-a)/2]+bruh[(b-a+1)/2]);
    else
        return 2*bruh[(b-a)/2];
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector <int> V(n+1);
    for (int i=1;i<=n;i++)
        cin >> V[i];

    int maxx= -1;
    int iloscMaxx= 0;

    for (int a=1;a<=n;a++)
        for (int b=a;b<=n;b++) {
            int mediana= wyliczMediane(a, b, V);    /// 2* mediana
            // cerr << " 2*mediana= " << mediana << endl;
            int iloscLiczb= b-a+1;

            if (maxx < iloscLiczb+mediana) {
                maxx= iloscLiczb+mediana;
                iloscMaxx= 1;
            }
            else if (maxx == iloscLiczb+mediana)
                iloscMaxx++;
        }

    cout << maxx << ' ' << iloscMaxx << '\n';


    return 0;
}