题意
链接: link.
input
2
5 2 3
1 2 3 1 2
4 3 3
1 1 2 3
output
YES
1 1 1 2 2
YES
1 2 2 3
首先看样例
5 2 3分别表示积木数量5,2表示要捏几个塔
每个塔不许没有积木,且题目说了,积木不会超过标准x=3,
要求最后你捏的每个塔的高度差不能超过x
输出每块积木是属于哪一个塔
不可能捏不成,为啥?因为一块积木造成的差不对大于x
思路
我们优先队列模拟贪心就够了,每次选择最爱的塔放积木为了偷懒,
我们不累加,我们累减
AC代码
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mp make_pair
const int N = 1E5 + 10;
int arr[N];
int main()
{
int t;
cin >> t;
while (t--)
{
priority_queue<pii> q;
int n, m, x;
cin >> n >> m >> x;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
for (int i = 1; i <= m; ++i)
q.push(mp(0, i));
cout << "YES" << endl;
for (int i = 1; i <= n; i++)
{
pair<int, int> res;
res = q.top();
q.pop();
cout << res.second << " ";
res.first -= arr[i];
q.push(res);
}
cout << endl;
}
//system("pause");
return 0;
}