To minimize the maximum value, we need to first calculate the maximum value in binary mode, and then greedy to achieve output in the format of the smallest on the left.
CodeAs follows:
# Include <iostream> # include <cstdlib> # include <cstring> # include <cstdio> # include <cmath> using namespace STD; int main () {# ifdef test freopen ("in.txt", "r", stdin); # endif int A [505], B [505]; int K, M, num; scanf ("% d", & num); While (Num --) {long left = 0, Right = 0, CT, to, mid; memset (B, 0, sizeof (B); scanf ("% d", & M, & K); For (INT I = 0; I <m; I ++) {scanf ("% d", & A [I]); right + = A [I];} while (left <Right) // returns the maximum {Ct = 0, To = 0; Mid = (left + right)/2; for (INT I = 0; I <m; I ++) {to + = A [I]; if (a [I]> mid) // when a single element is greater than the central value, you need to increase the value of mid {Ct = K; // make it jump out of break;} If (to >= mid) {If (CT> = k) break; CT ++; to = A [I] ;}}if (CT> K-1) Left = Mid + 1; else right = mid ;}for (INT CCT = 0, TOT = 0, I = m-1; I> = 0; I --) // greedy {tot + = A [I]; if (a [I]> mid) // a small error may occur when the maximum value is obtained in binary mode. When a single element is slightly greater than the maximum value, use this method to update the maximum value. Mid = A [I]; If (CCT <k-1 & (TOT> mid | I <(k-1)-CCT )) // when the interval value is greater than the maximum value or the number of remaining elements is equal to the number of remaining partitions, Division is required. {B [I] = 1; Tot = A [I]; ++ CCT ;}} for (INT I = 0; I <m; I ++) {printf ("% d % C", a [I], I! M-1? '': '\ N'); If (B [I]) printf ("/") ;}} return 0 ;}