CF1255B.Fridge Lockers

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a private fridge.

nn fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The owner of a fridge knows passcodes of all chains connected to it. A fridge can be open only if all chains connected to it are unlocked. For example, if a fridge has no chains connected to it at all, then any of nn people can open it.

For exampe, in the picture there are n=4n=4 people and 55 chains. The first person knows passcodes of two chains: 141-4 and 121-2 . The fridge 11 can be open by its owner (the person 11 ), also two people 22 and 44 (acting together) can open it.The weights of these fridges are a1,a2,,ana_1, a_2, \ldots, a_n . To make a steel chain connecting fridges uu and vv , you have to pay au+ava_u + a_v dollars. Note that the landlord allows you to create multiple chains connecting the same pair of fridges.

Hanh's apartment landlord asks you to create exactly mm steel chains so that all fridges are private. A fridge is private if and only if, among nn people living in the apartment, only the owner can open it (i.e. no other person acting alone can do it). In other words, the fridge ii is not private if there exists the person jj ( iji \ne j ) that the person jj can open the fridge ii .

For example, in the picture all the fridges are private. On the other hand, if there are n=2n=2 fridges and only one chain (which connects them) then both fridges are not private (both fridges can be open not only by its owner but also by another person).

Of course, the landlord wants to minimize the total cost of all steel chains to fulfill his request. Determine whether there exists any way to make exactly mm chains, and if yes, output any solution that minimizes the total cost.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases TT ( 1T101 \le T \le 10 ). Then the descriptions of the test cases follow.

The first line of each test case contains two integers nn , mm ( 2n10002 \le n \le 1000 , 1mn1 \le m \le n ) — the number of people living in Hanh's apartment and the number of steel chains that the landlord requires, respectively.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 0ai1040 \le a_i \le 10^4 ) — weights of all fridges.

输出格式

For each test case:

  • If there is no solution, print a single integer 1-1 .
  • Otherwise, print a single integer cc — the minimum total cost. The ii -th of the next mm lines contains two integers uiu_i and viv_i ( 1ui,vin1 \le u_i, v_i \le n , uiviu_i \ne v_i ), meaning that the ii -th steel chain connects fridges uiu_i and viv_i . An arbitrary number of chains can be between a pair of fridges.

If there are multiple answers, print any.

输入输出样例

  • 输入#1

    3
    4 4
    1 1 1 1
    3 1
    1 2 3
    3 3
    1 2 3
    

    输出#1

    8
    1 2
    4 3
    3 2
    4 1
    -1
    12
    3 2
    1 2
    3 1
首页