-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1048 - Conquering Keokradong_final.cpp
51 lines (47 loc) · 1.27 KB
/
1048 - Conquering Keokradong_final.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
#include <bits/stdc++.h>
using namespace std;
int campSite[1010], numCampSite, Night;
bool binarySearch( int expNum ){
int minTot = 0, part = 0;
for( int i=0; i<numCampSite; i++ ){
minTot += campSite[i];
if( minTot > expNum ){
part++;
minTot = campSite[i];
}
}return Night >= part;
}
int main()
{
freopen( "input.txt","r",stdin );
int t;
scanf( "%d",&t );
for( int T=1; T <= t; T++ ){
scanf( "%d %d", &numCampSite, &Night );
numCampSite++;
Night++;
int high = 0, low=0, mid, expectedAns;
for( int i=0; i < numCampSite; i++ ){
scanf( "%d",&campSite[i] );
high += campSite[i];
}
expectedAns = high;
while ( high >= low ){
mid = ( high + low )/2;
if( binarySearch( mid ) ){
expectedAns = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
printf( "Case %d: %d\n",T,mid );
for( int i=0, j = 0; i<Night; i++ ){
int sum = 0;
for( ;j<numCampSite; j++ ){
if( sum+campSite[i] > mid )break;
sum += campSite[i];
}printf( "%d\n",sum );
}
}return 0;
}