A8482 | Candy Shop
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The prestigious Codeforces kindergarten consists of $n$ kids, numbered $1$ through $n$ . Each of them are given allowance in rubles by their parents.
Today, they are going to the most famous candy shop in the town. The shop sells candies in packages: for all $i$ between $1$ and $m$ , inclusive, it sells a package containing exactly $i$ candies. A candy costs one ruble, so a package containing $x$ candies costs $x$ rubles.
The kids will purchase candies in turns, starting from kid 1. In a single turn, kid $i$ will purchase one candy package. Due to the highly competitive nature of Codeforces kindergarten, during a turn, the number of candies contained in the package purchased by the kid will always be strictly greater than the number of candies contained in the package purchased by the kid in the preceding turn (an exception is in the first turn: the first kid may purchase any package). Then, the turn proceeds to kid $i+1$ , or to kid $1$ if it was kid $n$ 's turn. This process can be ended at any time, but at the end of the purchase process, all the kids must have the same number of candy packages. Of course, the amount spent by each kid on the candies cannot exceed their allowance.
You work at the candy shop and would like to prepare the candies for the kids. Print the maximum number of candies that can be sold by the candy shop to the kids. If the kids cannot purchase any candy (due to insufficient allowance), print $0$ .
Today, they are going to the most famous candy shop in the town. The shop sells candies in packages: for all $i$ between $1$ and $m$ , inclusive, it sells a package containing exactly $i$ candies. A candy costs one ruble, so a package containing $x$ candies costs $x$ rubles.
The kids will purchase candies in turns, starting from kid 1. In a single turn, kid $i$ will purchase one candy package. Due to the highly competitive nature of Codeforces kindergarten, during a turn, the number of candies contained in the package purchased by the kid will always be strictly greater than the number of candies contained in the package purchased by the kid in the preceding turn (an exception is in the first turn: the first kid may purchase any package). Then, the turn proceeds to kid $i+1$ , or to kid $1$ if it was kid $n$ 's turn. This process can be ended at any time, but at the end of the purchase process, all the kids must have the same number of candy packages. Of course, the amount spent by each kid on the candies cannot exceed their allowance.
You work at the candy shop and would like to prepare the candies for the kids. Print the maximum number of candies that can be sold by the candy shop to the kids. If the kids cannot purchase any candy (due to insufficient allowance), print $0$ .
输入格式
The first line contains two space-separated integers $n$ and $m$ $(2<=n<=2·10^{5},2<=m<=5·10^{6},n<=m$ ), denoting the number of kids and the maximum number of candies in a package sold by the candy shop, respectively.
Then $n$ lines follow, each line will contain a single positive integer not exceeding  denoting the allowance of a kid in rubles. The allowances are given in order from kid $1$ to kid $n$ .
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is recommended to use cin, cout streams (also you may use %I64d specificator).
Then $n$ lines follow, each line will contain a single positive integer not exceeding  denoting the allowance of a kid in rubles. The allowances are given in order from kid $1$ to kid $n$ .
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is recommended to use cin, cout streams (also you may use %I64d specificator).
输出格式
Print a single integer denoting the maximum number of candies that can be sold by the candy shop.
输入输出样例
输入 #1
2 5 5 10
输出 #1
13
输入 #2
3 8 8 16 13
输出 #2
32
输入 #3
2 5000000 12500002500000 12500002500000
输出 #3
12500002500000
For the first example, one of the scenarios that will result in $13$ purchased candies is as follows.
- Turn 1. Kid 1 purchases 1 candy.
- Turn 2. Kid 2 purchases 3 candies.
- Turn 3. Kid 1 purchases 4 candies.
- Turn 4. Kid 2 purchases 5 candies.
- Turn 1. Kid 1 purchases 1 candy.
- Turn 2. Kid 2 purchases 3 candies.
- Turn 3. Kid 1 purchases 4 candies.
- Turn 4. Kid 2 purchases 5 candies.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted