CF1704C.Virus

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn houses numbered from 11 to nn on a circle. For each 1in11 \leq i \leq n - 1 , house ii and house i+1i + 1 are neighbours; additionally, house nn and house 11 are also neighbours.

Initially, mm of these nn houses are infected by a deadly virus. Each morning, Cirno can choose a house which is uninfected and protect the house from being infected permanently.

Every day, the following things happen in order:

  • Cirno chooses an uninfected house, and protect it permanently.
  • All uninfected, unprotected houses which have at least one infected neighbor become infected.

Cirno wants to stop the virus from spreading. Find the minimum number of houses that will be infected in the end, if she optimally choose the houses to protect.

Note that every day Cirno always chooses a house to protect before the virus spreads. Also, a protected house will not be infected forever.

输入格式

The input consists of multiple test cases. The first line contains a single integer tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases. Description of test cases follows.

The first line of each test case consists of two positive integers n,mn, m ( 5n1095 \leq n \leq 10^9 , 1mmin(n,105)1 \leq m \leq \min(n, 10^5) ) — the number of houses on the circle, and the number of houses that are initially infected.

The second line of each test case consists of mm distinct positive integers a1,a2,,ama_1, a_2, \cdots , a_m ( 1ain1 \leq a_i \leq n ) — the indices of the houses infected initially.

It is guaranteed that the sum of mm over all test cases does not exceed 10510^5 .

输出格式

For each test case, output an integer on a separate line, which is the minimum number of infected houses in the end.

输入输出样例

  • 输入#1

    8
    10 3
    3 6 8
    6 2
    2 5
    20 3
    3 7 12
    41 5
    1 11 21 31 41
    10 5
    2 4 6 8 10
    5 5
    3 2 5 4 1
    1000000000 1
    1
    1000000000 4
    1 1000000000 10 16

    输出#1

    7
    5
    11
    28
    9
    5
    2
    15

说明/提示

In the first test case:

At the start of the first day, house 33 , 66 , 88 are infected. Choose house 22 to protect.

At the start of the second day, house 33 , 44 , 55 , 66 , 77 , 88 , 99 are infected. Choose house 1010 to protect.

At the start of the third day, no more houses are infected.

In the second test case:

At the start of the first day, house 22 , 55 are infected. Choose house 11 to protect.

At the start of the second day, house 22 , 33 , 44 , 55 , 66 are infected. No more available houses can be protected.

首页