A14709 | Max Sum Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $c = [c_1, c_2, \dots, c_m]$ . An array $a = [a_1, a_2, \dots, a_n]$ is constructed in such a way that it consists of integers $1, 2, \dots, m$ , and for each $i \in [1,m]$ , there are exactly $c_i$ occurrences of integer $i$ in $a$ . So, the number of elements in $a$ is exactly $\sum\limits_{i=1}^{m} c_i$ .
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}. $$ </p><p>In other words, $f(a)$ is the total sum of distances between all pairs of equal elements.</p><p>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.
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}. $$ </p><p>In other words, $f(a)$ is the total sum of distances between all pairs of equal elements.</p><p>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 \le m \le 5 \cdot 10^5$ ) — the size of the array $c$ .
The second line contains $m$ integers $c_1, c_2, \dots, c_m$ ( $1 \le c_i \le 10^6$ ) — the array $c$ .
The second line contains $m$ integers $c_1, c_2, \dots, c_m$ ( $1 \le c_i \le 10^6$ ) — 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 $10^9 + 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 $10^6$ ones and its $f(a) = \sum\limits_{1 \le i < j \le 10^6}{j - i} = 166\,666\,666\,666\,500\,000$ and $166\,666\,666\,666\,500\,000 \bmod{10^9 + 7} = 499\,833\,345$ .
In the second example, the only possible array consists of $10^6$ ones and its $f(a) = \sum\limits_{1 \le i < j \le 10^6}{j - i} = 166\,666\,666\,666\,500\,000$ and $166\,666\,666\,666\,500\,000 \bmod{10^9 + 7} = 499\,833\,345$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted