300969: CF182B. Vasya's Calendar

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Vasya's Calendar

题意翻译

有一个记录日期的机器,它的日期上限为 $d$ ,即在第 $d+1$ 天它会重置为第 $1$ 天。 现在给出 nn 个月份和每个月份的天数 $a_i$ ,保证 $a_i \leq d$ 。 每天机器显示的日期都会加 11,如果当机器显示的日期和当前月份的日期不相同时,你就需要手动调整机器,每次可以让机器显示的日期加 $1$ (超过上限依然会重置)。 请求出你需要调整机器的次数。

题目描述

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 $ .

输入输出格式

输入格式


The first line contains the single number $ d $ — the maximum number of the day that Vasya's clock can show $ (1<=d<=10^{6}) $ . 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.

输出格式


Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.

输入输出样例

输入样例 #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.

Input

题意翻译

有一个记录日期的机器,它的日期上限为 $d$ ,即在第 $d+1$ 天它会重置为第 $1$ 天。 现在给出 nn 个月份和每个月份的天数 $a_i$ ,保证 $a_i \leq d$ 。 每天机器显示的日期都会加 11,如果当机器显示的日期和当前月份的日期不相同时,你就需要手动调整机器,每次可以让机器显示的日期加 $1$ (超过上限依然会重置)。 请求出你需要调整机器的次数。

加入题单

上一题 下一题 算法标签: