CF182B.Vasya's Calendar
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya lives in a strange world. The year has n months and the i-th month has a__i days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to d. It is guaranteed that a__i ≤ d for all i from 1 to n. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number d + 1, so after day number d it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day d is also followed by day 1.
Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.
A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the n-th month inclusive, considering that on the first day of the first month the clock display showed day 1.
瓦西娅生活在一个奇特的世界中。一年有 n 个月,第 i 个月有 ai 天。瓦西娅收到了一份新年礼物——一款不仅能显示时间、还能显示日期的时钟。
该时钟表盘可显示 1 到 d 之间的任意整数。题目保证对所有 i(1≤i≤n)均有 ai≤d。该时钟不记录当前月份,因此每当新的一天到来时,它仅将当前日期数字加一。时钟无法显示数字 d+1,故在显示日期 d 后,下一天将显示 1(即当前日期计数器归零重置)。该时钟的机械结构允许用户手动将日期数字加一;执行此操作时,d 的后继同样为 1。
瓦西娅每天开始时都会检查时钟上显示的日期数字。若该数字与当前月份的实际日期数字不符,则他手动将其加一。瓦西娅非常执着,会不断重复该操作,直至时钟显示的日期数字与当前月份的实际日期数字完全一致。
一年过去了,瓦西娅想知道:从第 1 个月的第 1 天起,至第 n 个月的最后一天止(含首尾两天),他总共手动将日期数字加一了多少次?已知在第 1 个月第 1 天开始时,时钟显示的日期为 1。
输入格式
The first line contains the single number d — the maximum number of the day that Vasya's clock can show (1 ≤ d ≤ 106).
The second line contains a single integer n — the number of months in the year (1 ≤ n ≤ 2000).
The third line contains n space-separated integers: a__i (1 ≤ a__i ≤ d) — the number of days in each month in the order in which they follow, starting from the first one.
第一行包含一个整数 d —— Vasya 的时钟所能显示的最大日期(1 ≤ d ≤ 106)。
第二行包含一个整数 n —— 一年中的月份数(1 ≤ n ≤ 2000)。
第三行包含 n 个用空格分隔的整数:ai(1 ≤ ai ≤ d)—— 按顺序(从第一个月开始)给出的每个月的天数。
输出格式
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
输出一个整数——即瓦西娅在去年手动将日期加 1 的次数。
输入输出样例
输入#1
4 2 2 2
输出#1
2
输入#2
5 3 3 4 3
输出#2
3
输入#3
31 12 31 28 31 30 31 30 31 31 30 31 30 31
输出#3
7
说明/提示
In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing.
- Day 2. Month 1. The clock shows 2. Vasya changes nothing.
- Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1.
- Day 2. Month 2. The clock shows 2. Vasya changes nothing.
In total, Vasya manually changed the day number by 1 exactly 2 times.
在第一个样例中,情况如下:
- 1 月 1 日:时钟显示 1,瓦西娅不进行任何操作。
- 1 月 2 日:时钟显示 2,瓦西娅不进行任何操作。
- 2 月 1 日:时钟显示 3,瓦西娅手动将日期加 1;此时时钟显示 4;瓦西娅再次手动将日期加 1;此时时钟显示 1。
- 2 月 2 日:时钟显示 2,瓦西娅不进行任何操作。
总计,瓦西娅恰好手动将日期加 1 共 2 次。
输入解题思路,AI测评打分。不知道怎么写?