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 <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long int lli;

int main() {
    lli n;
    scanf("%lli", &n);
    vector<lli> nums(n);
    for (int i = 0; i < n; i++) {
        int num;
        scanf("%d", &num);
        nums[i] = num;
    }
    int maxSum = 2 * n + 1;
    int median = n + 1;
    int count = 1;
    int left = 0, right = n-1;
    while (left < right) {
        if (nums[left] <= median) {
            count++;
            median++;
            left++;
        }
        if (nums[right] <= median) {
            count++;
            median++;
            right--;
        }
    }
    cout << maxSum << " " << count << '\n';
    return 0;
}