https://codeforces.com/problemset/problem/1515/C
开m个小根堆,尽可能的平分。因为题目给出任意的俩数的差是小于x的,故一定有解。
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*3+10;
typedef pair<int,int> PII;
int a[N],ans[N],t,n,m,x;
int main(void)
{
cin>>t;
while(t--)
{
cin>>n>>m>>x;
for(int i=0;i<n;i++) cin>>a[i];
priority_queue<PII,vector<PII>,greater<PII>>heap;
for(int i=0;i<m;i++) heap.push({
0,i});
for(int i=0;i<n;i++)
{
auto u=heap.top(); heap.pop();
u.first+=a[i],ans[i]=u.second;
heap.push(u);
}
puts("YES");
for(int i=0;i<n;i++) cout<<ans[i]+1<<" ";
cout<<endl;
}
return 0;
}