比赛 4043级2023省选练习赛2 评测结果 WWWWWWWWWWWWWWWWWWWW
题目名称 制作菜品 最终得分 0
用户昵称 zxhhh 运行时间 0.060 s
代码语言 C++ 内存使用 2.04 MiB
提交时间 2023-03-06 20:57:18
显示代码纯文本
#include <bits/stdc++.h>

using namespace std;

int n, m, k, T, d[505];
int idx[5005][2], g[5005][2], op[5005];

struct node {
	int idx, k;
	bool operator < (const node & rhs) const {
		return k < rhs.k;
	}
};

multiset <node> st;

int main () {
	freopen("dish.in", "r", stdin);
	freopen("dish.out", "w", stdout);
	cin >> T;
	while (T--) {
		int z = 0, flag = 1;
		st.clear();
		cin >> n >> m >> k;
		for (int i = 1;i <= n;i++) cin >> d[i], st.insert((node){i, d[i]});
		while (st.size() > 1) {
			node x = *st.begin(), y = *(--st.end());
			if (x.k + y.k < k) {
				flag = 0;
				break;
			}
			if (x.k == 0) {
				st.erase(st.find(x));
				continue;
			}
			if (x.k >= k) {
				st.erase(st.find(x));
				x.k -= k;
				op[++z] = 0; g[z][0] = k; idx[z][0] = x.idx;
				st.insert(x);
			}
			else {
				st.erase(st.find(x)); st.erase(st.find(y));
				int p = k - x.k; y.k -= p;
				op[++z] = 1; g[z][0] = x.k, g[z][1] = p; idx[z][0] = x.idx, idx[z][1] = y.idx;
				st.insert(y);
			}
		}
		node las = *st.begin();
		if (las.k != k) {
			flag = 0;
		}
		else op[++z] = 0, g[z][0] = k, idx[z][0] = las.idx;
		if (!flag) {
			cout <<-1 << endl;
		}
		else {
			for (int i = 1;i <= z;i++) {
				if(op[i] == 1) {
					cout << idx[i][0] <<" " << g[i][0] << " " <<idx[i][1] << " " << g[i][1] << endl;
				}
				else cout << idx[i][0] << " " << g[i][0] << endl;
			}
		}
	}
	return 0;
}