D. Productive Meeting (大根堆)

放到堆里,每次取出堆顶的两个元素来判断就好了

// Problem: D. Productive Meeting
// Contest: Codeforces - Codeforces Round #744 (Div. 3)
// URL: https://codeforces.com/contest/1579/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<list>
#include<unordered_map>
using namespace std;
#define ff first
#define ss second
#define lowbit(x) (x&-x)
#define pf(a) printf("%d\n",a)
#define mem(x,y) memset(x,y,sizeof(x))
#define dbg(x) cout << #x << " = " << x << endl
#define rep(i,l,r) for(int i = l; i <= r; i++)
#define fep(i,a,b) for(int i=b; i>=a; --i)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;


const int N=2e5+100;
int n;

struct node{
	int l,r;
}ans[N];

void solve()
{
	priority_queue<PII, vector<PII>, less<PII> >s;
	scanf("%d", &n);
	rep(i,1,n)
	{
		int tmp;
		cin >> tmp;
		s.push({tmp,i});
	}
	
	int cnt = 0;
	while(true)
	{
		auto a = s.top(); s.pop();
		auto b = s.top(); s.pop();
		if(a.ff==0 or b.ff == 0) break;
		else
		{
			ans[cnt++] = {a.ss, b.ss};
			s.push({a.ff-1,a.ss});
			s.push({b.ff-1,b.ss});
			
		}
	}
	cout << cnt << endl;
	for(int i = 0; i < cnt; i++)
	{
		cout << ans[i].l << " " << ans[i].r << endl;
	}
	 
}

int main()
{

	int Case;scanf("%d", &Case);
	while(Case--)
		solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sloppy People vs. Neat People Sloppy people and neat people are two different types of individuals with distinct personality traits. Sloppy people tend to be more relaxed and carefree, while neat people are often more organized and detail-oriented. Both types of people have their own unique strengths and weaknesses. Sloppy people are often creative and spontaneous. They tend to prioritize fun and enjoyment over order and structure. They are comfortable with chaos and can adapt easily to changing situations. They are also great at improvising and finding new solutions to problems. However, their lack of organization can sometimes lead to disarray and confusion. They may struggle to meet deadlines or remember important tasks. On the other hand, neat people prefer structure and order. They like to have a plan and stick to it. They are detail-oriented and take pride in their work. They are often reliable and responsible. They are also great at managing their time and resources efficiently. However, their attention to detail can sometimes lead to perfectionism and rigidity. They may struggle to be flexible or adapt when things don't go according to plan. In terms of living spaces, sloppy people tend to have cluttered and messy environments. They may have clothes strewn about or dishes piled up in the sink. Neat people, on the other hand, prefer clean and organized spaces. They may have a place for everything and everything in its place. They like to keep their living spaces tidy and free of clutter. In conclusion, both sloppy people and neat people have their own unique strengths and weaknesses. Sloppy people tend to be creative and adaptable, while neat people are organized and responsible. It's important to recognize and appreciate these differences, as they can add diversity and balance to our lives. Whether you're a sloppy person or a neat person, it's important to embrace your strengths and work on improving your weaknesses. By doing so, you can create a more fulfilling and productive life.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值