CF1612G.Max Sum Array
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array c=[c1,c2,…,cm] . An array a=[a1,a2,…,an] is constructed in such a way that it consists of integers 1,2,…,m , and for each i∈[1,m] , there are exactly ci occurrences of integer i in a . So, the number of elements in a is exactly i=1∑mci .
Let's define for such array a the value f(a) as $$$$f(a) = \sum_{\substack{1 \le i < j \le n\ a_i = a_j}}{j - i}. $$
In other words, f(a) is the total sum of distances between all pairs of equal elements.
Your task is to calculate the maximum possible value of f(a) and the number of arrays yielding the maximum possible value of f(a)$$. Two arrays are considered different, if elements at some position differ.
输入格式
The first line contains a single integer m ( 1≤m≤5⋅105 ) — the size of the array c .
The second line contains m integers c1,c2,…,cm ( 1≤ci≤106 ) — the array c .
输出格式
Print two integers — the maximum possible value of f(a) and the number of arrays a with such value. Since both answers may be too large, print them modulo 109+7 .
输入输出样例
输入#1
6 1 1 1 1 1 1
输出#1
0 720
输入#2
1 1000000
输出#2
499833345 1
输入#3
7 123 451 234 512 345 123 451
输出#3
339854850 882811119
说明/提示
In the first example, all possible arrays a are permutations of [1,2,3,4,5,6] . Since each array a will have f(a)=0 , so maximum value is f(a)=0 and there are 6!=720 such arrays.
In the second example, the only possible array consists of 106 ones and its f(a)=1≤i<j≤106∑j−i=166666666666500000 and 166666666666500000mod109+7=499833345 .