//题目要求的是每一个点最少要有两条边连接,所以可以先构成一个环。然后再把剩余的最短的边连接起来
#include<iostream>
#include<algorithm>
using namespace std ;
const int N=;
int n,m;
struct edge {
int num;
int w;
} a[N];
int T;
bool cmp(edge a,edge b) {
return a.w<b.w;
}
void solve() {
int ans=;
for(int i=; i<=n; i++) {
ans+=*a[i].w;
}
ans+=(m-n)*(a[].w+a[].w);
cout<<ans<<endl;
for(int i=; i<n; i++) cout<<i<<" "<<i+<<endl;
cout<<n<<" "<<""<<endl;
for(int i=; i<=m-n; i++) cout<<a[].num<<" "<<a[].num<<endl;
}
int main() {
cin>>T;
while(T--) {
cin>>n>>m;
for(int i=; i<=n; i++) {
cin>>a[i].w;
a[i].num=i;
}
if(n<=||m<n) {
cout<<"-1"<<endl;
continue;
}
sort(a+,a++n,cmp);
solve();
}
return ;
}

Codeforces Round #601 (Div. 2) B Fridge Lockers的更多相关文章

  1. Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)

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

  2. 【cf比赛记录】Codeforces Round #601 (Div. 2)

    Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...

  3. Codeforces Round #601 (Div. 2)

    传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...

  4. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)

    Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...

  5. Codeforces Round #601 (Div. 2) E1 Send Boxes to Alice (Easy Version)

    #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int a[N]; int n; bool pr ...

  6. Codeforces Round #601 (Div. 2) D Feeding Chicken

    //为了连贯,采取一条路形式,从第一行开始 也就是s型 #include <bits/stdc++.h> using namespace std; ; char str[MAXN][MAX ...

  7. Codeforces Round #601 (Div. 2) C League of Leesins

    把每一次输入的一组数字存下来,然后把每个数字出现的组数存下来 然后找只出现过一次的数字a,那么这个数字a不是开头就是结尾,默认为开头(是哪个都无所谓),然后去找和它出现在同一组的两个数字b和c,而b和 ...

  8. Codeforces Round #601 (Div. 2) A Changing Volume

    好吧,其实我拿到这个题的时候,首先想到了bfs,写完之后,开开森森的去交代码,却在第二个数据就TEL,然后优化半天,还是不行. 最终,我盯着1,2,5发呆半天,wc,然后直接贪心 #include&l ...

  9. Codeforces Round #601 (Div. 2)E(寻找质因子,DP)

    先分解质因数,对于当前a[i],假设当前的质因数为x,这个位置要满足能被k整除,有两个可能,要么是它向后一个转移x%k个,要么是后一个向它转移k-x%k个. 对于每一个a[i]满足后,因为只会对下一个 ...

随机推荐

  1. [Python]爬取 游民星空网站 每周精选壁纸(1080高清壁纸) 网络爬虫

    一.检查 首先进入该网站的https://www.gamersky.com/robots.txt页面 给出提示: 弹出错误页面 注: 网络爬虫:自动或人工识别robots.txt,再进行内容爬取 约束 ...

  2. 前端开发神器 VSCode 使用总结

    VSCode 是微软出品的,基于 Electron 和 TypeScript 的,集成了 git 版本管理和命令行终端,而且开源稳定,插件丰富,再搭配一款 Chrome 浏览器,可以说是前端开发神器了 ...

  3. TotalUninstall6破解步骤卸载软件更彻底更专业

    软件包分享,这里使用的是6.24版本 链接:https://pan.baidu.com/s/1aVd6bclk5A6puyWBfAOA2A提取码:mhl9 接下来开始安装 安装步骤: 点击安装.基本上 ...

  4. Wireshark下载地址

    官方下载地址: https://www.wireshark.org/download.html

  5. hdu6162

    这题一开始把我看愣了.难道是线段树套树状数组?空间根本开不下好不好!!! 后来想到维护区间极值,从而排除不必要情况,降低复杂度. 无需修改,码量顿减…… 注意,同一组数据放一行,注意行末空格. #in ...

  6. Quartz.NET - 教程 4: 更多关于触发器

    译者注: 目录在这 [译]Quartz.NET 3.x 教程 译者注: 原文在这 Lesson 4: More About Triggers 跟作业一样, 触发器也相当容易使用, 但确实包含各种可定制 ...

  7. JavaScript DOM–事件操作

    事件 注册事件 给元素添加事件,为注册事件或者绑定事件 注册事件两种方式 传统方式 监听事件方式 事件监听 addEventListener() 事件监听 (IE9以上) eventTarget.ad ...

  8. P2048 [NOI2010]超级钢琴 [堆+st表]

    考虑只能取长度为 [L,R] 的,然后不难想到用堆搞. 搞个前缀和的st表,里面维护的是一个 最大值的位置 struct rmq { int mx[N][20] ; void qwq(int n) { ...

  9. MVC5+EF6 入门完整教程八:数据迁移

    https://www.cnblogs.com/miro/p/4164076.html

  10. js数据类型1

    1. 分类(2大类) 基本(值)类型--5种 Number: 任意数值 String: 任意文本 Boolean: true/false undefined: undefined null: null ...