CF1255B Fridge Lockers 题解
极其水的一道题
思路
大家都知道,如果只有两个冰箱,无论有多少条铁链,两个人都可以互相开锁(不会是私有的),故如果
而如果
只有在
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n,m,cnt;
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>m;
c=0;
for(int j=1,x=0;j<=n;j++) cin>>x,c+=x;
if(n<3||m<n) cout<<"-1"<<endl,continue;
cout<<c+c<<endl;
for(int k=1;k<n;k++) cout<<k<<" "<<k+1<<endl;
cout<<n<<" "<<1<<endl;
}
return 0;
}