CF859F.Ordering T-Shirts
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
又到了 Start[c]up 比赛的时间,这意味着需要订购 T 恤。为了尽快发货,我们决定今年在正式比赛开始前就提前订购所有必需的 T 恤。排名前 C 名的参赛者将获得 T 恤,但我们显然还不知道最终哪些参赛者会进入前 C 名。我们的计划是:在正式比赛前先收集所有参赛者的 T 恤尺码信息,然后订购足够数量的 T 恤,以确保无论最终哪 C 名参赛者获奖,我们都拥有对应尺码的 T 恤可供发放。
为收集参赛者的 T 恤尺码,我们将发送一份问卷调查。该问卷允许每位参赛者指定一个期望的 T 恤尺码,或指定两个相邻的 T 恤尺码。若某位参赛者指定了两个尺码,则表示他/她可接受其中任意一个尺码。
你可能已经意识到,这一方案可能导致订购大量不必要的 T 恤。我们希望你能帮助我们确定:为确保无论比赛结果如何都能成功发放 T 恤,所需订购的 T 恤的最少数量是多少?
输入格式
Input will begin with two integers N and C (1 ≤ N ≤ 2·105, 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 ≤ 108). 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.
输入的第一行包含两个整数 N 和 C(1≤N≤2⋅105,1≤C),分别表示 T 恤尺码的种类数和待发放的 T 恤件数。
接下来的一行包含 2⋅N−1 个整数 s1 到 s2⋅N−1(0≤si≤108)。
- 当 i 为奇数时,si 表示希望获得第 2i+1 号尺码 T 恤的参赛者人数;
- 当 i 为偶数时,si 表示可接受第 2i 号或第 2i+1 号尺码 T 恤的参赛者人数。
保证 C 不超过参赛者总人数。
输出格式
Print the minimum number of T-shirts we need to buy.
输出我们需要购买的 T 恤的最少数量。
输入输出样例
输入#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.
在第一个示例中,我们可以每种尺寸各购买 100 个。
输入解题思路,AI测评打分。不知道怎么写?