#P9053. [PA 2021] Ranking sklepów internetowych

[PA 2021] Ranking sklepów internetowych

Problem Description

You are given a permutation aa of length nn.

Define the weight of an interval [l,r][l, r] as follows: sort the numbers in the interval in increasing order. Let xx be the interval length (that is, rl+1r - l + 1), and let yy be the median of the interval. Then the weight of this interval is x+2yx + 2y.

Among all n(n+1)2\frac{n(n + 1)}{2} intervals, find the maximum weight and the number of intervals whose weight equals this maximum.


Definition of the median:

Take a strictly increasing sequence aa of length nn as an example.

  • If nn is odd, the median is an+12a_{\frac{n + 1}{2}}.
  • If nn is even, the median is an2+an2+12\frac{a_{\frac{n}{2}} + a_{\frac{n}{2} + 1}}{2}.

Input Format

The first line contains an integer nn.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n.

Output Format

Output one line with two integers: the maximum weight and the number of intervals that achieve this maximum weight.

5
1 4 3 5 2
11 5

Hint

For 100%100\% of the testdata, 1n1061 \leq n \leq 10^6, 1ain1 \leq a_i \leq n.

Translated by ChatGPT 5