Each time you write your own priority queue, there will be a very good sense.
All containers are queued, tasks are arranged in a descending order, and each task is assigned to the currently idle container.
The NWA was not output during the first submission.
# Include <stdio. h> # include <string. h> # include <stdlib. h >#include <queue> using namespace STD; # define n 100005 struct point {int X, Y; int ID;} A [n]; struct node {int X, ID; bool friend operator <(node X, node y) {return y. x <X. X ;}} B [105]; int CMP (const void * a, const void * B) {point * C, * D; C = (point *); D = (point *) B; return D-> X-C-> X;} int CMP1 (const void * a, const void * B) {return (* (point *) ). ID-(* (point *) B ). ID;} int main () {int t; scanf ("% d", & T); While (t --) {int n, m; scanf ("% d", & N, & M); int I; for (I = 0; I <n; I ++) {scanf ("% d", & A [I]. x); A [I]. id = I;} qsort (A, N, sizeof (A [0]), CMP); priority_queue <node> q; node cur; for (I = 0; I <m; I ++) {B [I]. X = 0; B [I]. id = I; q. push (B [I]) ;}for (I = 0; I <n; I ++) {cur = Q. top (); q. pop (); cur. X + = A [I]. x; A [I]. y = cur. ID; q. push (cur);} qsort (A, N, sizeof (A [0]), CMP1); printf ("% d \ n", N ); for (I = 0; I <n-1; I ++) printf ("% d", a [I]. y); printf ("% d \ n", a [I]. y);} return 0 ;}