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.
33 lines
855 B
C++
33 lines
855 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
typedef long long ll;
|
|
const int N = 1e5 + 50;
|
|
ll a[N];
|
|
int main()
|
|
{
|
|
int T, n, k, ans;
|
|
scanf("%d", &T);
|
|
for (int t = 1; t <= T; t++)
|
|
{
|
|
scanf("%d%d", &n, &k);
|
|
for (int i = 0; i < n; i++) scanf("%lld", a + i);
|
|
ll sum = accumulate(a, a + n, 0ll);
|
|
if (sum % k)
|
|
ans = -1;
|
|
else
|
|
{
|
|
ll tgt = sum / k, cur = 0;
|
|
ans = -1;
|
|
deque<ll> D(a, a + n);
|
|
while (!D.empty())
|
|
{
|
|
int cur = 0;
|
|
while (cur < tgt && !D.empty())
|
|
cur += D.front(), D.pop_front(), ans++;
|
|
if (cur > tgt) D.push_front(cur - tgt), ans++;
|
|
}
|
|
}
|
|
printf("Case #%d: %d\n", t, ans);
|
|
}
|
|
return 0;
|
|
} |