You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define CRP(t, x) const t &x
|
|
#define OPL(t, x) bool operator<(CRP(t, x)) const
|
|
#define FIL(x, v) memset(x, v, sizeof(x))
|
|
#define CLR(x) FIL(x, 0)
|
|
#define NE1(x) FIL(x, -1)
|
|
#define INF(x) FIL(x, 0x3f)
|
|
typedef long long ll, i64;
|
|
int a[1050];
|
|
int calc(int n, int V)
|
|
{
|
|
int c = 0, r = 0;
|
|
multiset<int> S{a, a + n};
|
|
while (!S.empty())
|
|
{
|
|
auto ite = S.upper_bound(r);
|
|
if (ite == S.begin()) c++, r = V, ite = S.upper_bound(r);
|
|
r -= *--ite;
|
|
S.erase(ite);
|
|
}
|
|
return c;
|
|
}
|
|
int main()
|
|
{
|
|
int T, n, K;
|
|
scanf("%d", &T);
|
|
for (int t = 1; t <= T; t++)
|
|
{
|
|
scanf("%d%d", &n, &K);
|
|
for (int i = 0; i < n; i++) scanf("%d", a + i);
|
|
sort(a, a + n);
|
|
for (int st = accumulate(a, a + n, K - 1) / K;; st++)
|
|
if (calc(n, st) <= K)
|
|
{
|
|
printf("Case #%d: %d\n", t, st);
|
|
break;
|
|
}
|
|
}
|
|
return 0;
|
|
} |