-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
39 lines (39 loc) · 1.03 KB
/
C.cpp
File metadata and controls
39 lines (39 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;
signed main() {
cout.tie();
int t;
cin>>t;
while(t--){
int n,m,x;
cin>>n>>m>>x;
vector<pair<int,int>>blocks(n);
multiset<pair<int,int>>pq;
for(int i =1 ; i <=m;i++){
pq.insert({0,i});
}
for(int i = 0 ; i<n;i++){
cin>>blocks[i].first;
blocks[i].second=i;
}
sort(blocks.begin(), blocks.end());
vector<int>ans(n);
for(int i = n-1 ; i >=0;i--){
auto ele =*pq.begin();
pq.erase(*pq.begin());
ele.first+=blocks[i].first;
ans[blocks[i].second]=ele.second;
pq.insert(ele);
}
auto ele = *pq.begin();
auto eles = *pq.rbegin();
if(abs(ele.first)-abs(eles.first)>x){
cout<<"NO"<<endl;
}
else {
cout << "YES" << endl;
for (auto ele: ans)cout << ele << ' ';
cout << endl;
}
}
}