A12978 | Heating
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has $n$ rooms. In the $i$ -th room you can install at most $c_i$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $k$ sections is equal to $k^2$ burles.
Since rooms can have different sizes, you calculated that you need at least $sum_i$ sections in total in the $i$ -th room.
For each room calculate the minimum cost to install at most $c_i$ radiators with total number of sections not less than $sum_i$ .
Your house has $n$ rooms. In the $i$ -th room you can install at most $c_i$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $k$ sections is equal to $k^2$ burles.
Since rooms can have different sizes, you calculated that you need at least $sum_i$ sections in total in the $i$ -th room.
For each room calculate the minimum cost to install at most $c_i$ radiators with total number of sections not less than $sum_i$ .
输入格式
The first line contains single integer $n$ ( $1 \le n \le 1000$ ) — the number of rooms.
Each of the next $n$ lines contains the description of some room. The $i$ -th line contains two integers $c_i$ and $sum_i$ ( $1 \le c_i, sum_i \le 10^4$ ) — the maximum number of radiators and the minimum total number of sections in the $i$ -th room, respectively.
Each of the next $n$ lines contains the description of some room. The $i$ -th line contains two integers $c_i$ and $sum_i$ ( $1 \le c_i, sum_i \le 10^4$ ) — the maximum number of radiators and the minimum total number of sections in the $i$ -th room, respectively.
输出格式
For each room print one integer — the minimum possible cost to install at most $c_i$ radiators with total number of sections not less than $sum_i$ .
输入输出样例
输入 #1
4 1 10000 10000 1 2 6 4 6
输出 #1
100000000 1 18 10
In the first room, you can install only one radiator, so it's optimal to use the radiator with $sum_1$ sections. The cost of the radiator is equal to $(10^4)^2 = 10^8$ .
In the second room, you can install up to $10^4$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there $7$ variants to install radiators: $[6, 0]$ , $[5, 1]$ , $[4, 2]$ , $[3, 3]$ , $[2, 4]$ , $[1, 5]$ , $[0, 6]$ . The optimal variant is $[3, 3]$ and it costs $3^2+ 3^2 = 18$ .
In the second room, you can install up to $10^4$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there $7$ variants to install radiators: $[6, 0]$ , $[5, 1]$ , $[4, 2]$ , $[3, 3]$ , $[2, 4]$ , $[1, 5]$ , $[0, 6]$ . The optimal variant is $[3, 3]$ and it costs $3^2+ 3^2 = 18$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted