-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkout_kickstart.cpp
More file actions
68 lines (64 loc) · 1.32 KB
/
workout_kickstart.cpp
File metadata and controls
68 lines (64 loc) · 1.32 KB
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
#include <iostream>
using namespace std;
using ll = long long;
int numTest;
int n, k; // n = number of elements, k = # of additional sess
int a[100005];
/*1
3 1
100 200 230*/
void dbg(int x)
{
cout << x << endl;
}
int main()
{
cin >> numTest;
for (int i = 0; i < numTest; i++)
{
cin >> n >> k;
int max_diff = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
cout << "Case #" << i + 1 << ": ";
int lo = 1;
int hi = 1000000007;
int ans = -1;
int gap[n];
for (int i = 1; i < n; i++)
{
gap[i] = a[i] - a[i - 1];
}
// gap: 200 30
while (lo <= hi)
{
int count = 0; // should this be here
int mid = lo + (hi - lo) / 2;
for (int i = 01; i < n; i++)
{
count += gap[i] / mid;
if (gap[i] % mid == 0)
{
count--;
}
}
if (count <= k)
{
ans = mid;
hi = mid - 1;
}
else if (count > k)
{
lo = mid + 1;
}
else
{
ans = mid;
}
}
cout << ans << endl;
}
return 0;
}