A14010 | Strange Partition
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $a$ of length $n$ , and an integer $x$ . You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their sum. For example, if the initial array was $[3, 6, 9]$ , in a single operation one can replace the last two elements by their sum, yielding an array $[3, 15]$ , or replace the first two elements to get an array $[9, 9]$ . Note that the size of the array decreases after each operation.
The beauty of an array $b=[b_1, \ldots, b_k]$ is defined as $\sum_{i=1}^k \left\lceil \frac{b_i}{x} \right\rceil$ , which means that we divide each element by $x$ , round it up to the nearest integer, and sum up the resulting values. For example, if $x = 3$ , and the array is $[4, 11, 6]$ , the beauty of the array is equal to $\left\lceil \frac{4}{3} \right\rceil + \left\lceil \frac{11}{3} \right\rceil + \left\lceil \frac{6}{3} \right\rceil = 2 + 4 + 2 = 8$ .
Please determine the minimum and the maximum beauty you can get by performing some operations on the original array.
The beauty of an array $b=[b_1, \ldots, b_k]$ is defined as $\sum_{i=1}^k \left\lceil \frac{b_i}{x} \right\rceil$ , which means that we divide each element by $x$ , round it up to the nearest integer, and sum up the resulting values. For example, if $x = 3$ , and the array is $[4, 11, 6]$ , the beauty of the array is equal to $\left\lceil \frac{4}{3} \right\rceil + \left\lceil \frac{11}{3} \right\rceil + \left\lceil \frac{6}{3} \right\rceil = 2 + 4 + 2 = 8$ .
Please determine the minimum and the maximum beauty you can get by performing some operations on the original array.
输入格式
The first input line contains a single integer $t$ — the number of test cases ( $1 \le t \le 1000$ ).
The first line of each test case contains two integers $n$ and $x$ ( $1 \leq n \leq 10^5$ , $1 \leq x \leq 10^9$ ).
The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ), the elements of the array $a$ .
It is guaranteed that the sum of values of $n$ over all test cases does not exceed $10^5$ .
The first line of each test case contains two integers $n$ and $x$ ( $1 \leq n \leq 10^5$ , $1 \leq x \leq 10^9$ ).
The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ), the elements of the array $a$ .
It is guaranteed that the sum of values of $n$ over all test cases does not exceed $10^5$ .
输出格式
For each test case output two integers — the minimal and the maximal possible beauty.
输入输出样例
输入 #1
2 3 3 3 6 9 3 3 6 4 11
输出 #1
6 6 7 8
In the first test case the beauty of the array does not change if we perform any operations.
In the second example we can leave the array unchanged to attain the maximum beauty, and to get the minimum beauty one can replace two elements $4$ and $11$ with their sum, yielding an array $[6, 15]$ , which has its beauty equal to $7$ .
In the second example we can leave the array unchanged to attain the maximum beauty, and to get the minimum beauty one can replace two elements $4$ and $11$ with their sum, yielding an array $[6, 15]$ , which has its beauty equal to $7$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted