A11231 | Ordering T-Shirts
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It's another Start\[c\]up, and that means there are T-shirts to order. In order to make sure T-shirts are shipped as soon as possible, we've decided that this year we're going to order all of the necessary T-shirts before the actual competition. The top $C$ contestants are going to be awarded T-shirts, but we obviously don't know which contestants that will be. The plan is to get the T-Shirt sizes of all contestants before the actual competition, and then order enough T-shirts so that no matter who is in the top $C$ we'll have T-shirts available in order to award them.
In order to get the T-shirt sizes of the contestants, we will send out a survey. The survey will allow contestants to either specify a single desired T-shirt size, or two adjacent T-shirt sizes. If a contestant specifies two sizes, it means that they can be awarded either size.
As you can probably tell, this plan could require ordering a lot of unnecessary T-shirts. We'd like your help to determine the minimum number of T-shirts we'll need to order to ensure that we'll be able to award T-shirts no matter the outcome of the competition.
In order to get the T-shirt sizes of the contestants, we will send out a survey. The survey will allow contestants to either specify a single desired T-shirt size, or two adjacent T-shirt sizes. If a contestant specifies two sizes, it means that they can be awarded either size.
As you can probably tell, this plan could require ordering a lot of unnecessary T-shirts. We'd like your help to determine the minimum number of T-shirts we'll need to order to ensure that we'll be able to award T-shirts no matter the outcome of the competition.
输入格式
Input will begin with two integers $N$ and $C$ ( $1<=N<=2·10^{5}$ , $1<=C$ ), the number of T-shirt sizes and number of T-shirts to be awarded, respectively.
Following this is a line with $2·N-1$ integers, $s_{1}$ through $s_{2·N-1}$ $(0<=s_{i}<=10^{8})$ . For odd $i$ , $s_{i}$ indicates the number of contestants desiring T-shirt size $((i+1)/2)$ . For even $i$ , $s_{i}$ indicates the number of contestants okay receiving either of T-shirt sizes $(i/2)$ and $(i/2+1)$ . $C$ will not exceed the total number of contestants.
Following this is a line with $2·N-1$ integers, $s_{1}$ through $s_{2·N-1}$ $(0<=s_{i}<=10^{8})$ . For odd $i$ , $s_{i}$ indicates the number of contestants desiring T-shirt size $((i+1)/2)$ . For even $i$ , $s_{i}$ indicates the number of contestants okay receiving either of T-shirt sizes $(i/2)$ and $(i/2+1)$ . $C$ will not exceed the total number of contestants.
输出格式
Print the minimum number of T-shirts we need to buy.
输入输出样例
输入 #1
2 200 100 250 100
输出 #1
200
输入 #2
4 160 88 69 62 29 58 52 44
输出 #2
314
In the first example, we can buy $100$ of each size.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted