-
Notifications
You must be signed in to change notification settings - Fork 3
/
lightoj 1048.cpp
92 lines (77 loc) · 1.48 KB
/
lightoj 1048.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 1005
int n,k;
int ar[mx];
bool possible(int val)
{
int hate_ace=val;
int cnt=0;
for(int i=1;i<=n+1;i++)
{
if(ar[i]>val)return false;
if(hate_ace>=ar[i])hate_ace-=ar[i];
else
{
cnt++;
hate_ace=val-ar[i];
if(cnt>k)return false;
}
}
return true;
}
void solve(int ii)
{
scanf("%d%d",&n,&k);
int lo=0,high=0;
for(int i=1;i<=n+1;i++){
int x;
scanf("%d",&ar[i]);
lo=max(lo,ar[i]);
high+=ar[i];
}
while(lo<=high)
{
int mid=(lo+high)/2;
if(possible(mid))
{
high=mid-1;
}
else lo=mid+1;
}
while(possible(high)==false)high++;
printf("Case %d: %d\n",ii,high);
int tem=0,cnt=0;
for(int i=1;i<=n+1;i++)
{
if(tem+ar[i]>high)
{
printf("%d\n",tem);
tem=ar[i];
cnt++;
}
else if(tem+ar[i]==high)
{
printf("%d\n",tem+ar[i]);
tem=0;
cnt++;
}
else if(n+1-i==k-cnt)
{
printf("%d\n",ar[i]+tem);
tem=0;
cnt++;
}
else tem+=ar[i];
}
}
int main()
{
int t;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
scanf("%d",&t);
for(int i=1;i<=t;i++)solve(i);
return 0;
}