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
#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n;
    cin>>n;

    int a[n], v2i[n];
    for (int i=0; i<n; ++i) {
        cin>>a[i];
        v2i[a[i]-1] = i;
    }

    ll maxV = 2*n+1, cnt=1;

    int L=v2i[n-1], R=v2i[n-1], bCnt=1, req=2;
    for (int m=2*n-1; m>=1; --m) {
        int v = m/2, i=v2i[v-1];
        L = min(L, i), R = max(R, i);
        int lCnt=R-L-bCnt;

        if (bCnt == req/2) cnt += min({L, n-1-R, R-L-lCnt});

        if (m%2 == 0) ++bCnt;
        ++req;
    }

    cout<<maxV<<" "<<cnt<<endl;
}