-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbee1579.cpp
More file actions
63 lines (49 loc) · 947 Bytes
/
Copy pathbee1579.cpp
File metadata and controls
63 lines (49 loc) · 947 Bytes
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
/*
* Contest : Beecrowd
* Problem : 1579 - Transporte de Painéis Solares
* Link : https://judge.beecrowd.com/pt/problems/view/1579
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int n, c, f, tc;
vector<int> p;
bool isValid(int x) {
int sum = 0, cnt = 1;
for (auto v : p) {
sum += v;
if (sum > x) {
cnt++;
sum = v;
}
}
return cnt <= c;
}
int bs() {
int l = *max_element(p.begin(), p.end()),
r = accumulate(p.begin(), p.end(), 0),
mid, ans = -1;
while (l <= r) {
mid = l + (r - l) / 2;
if (isValid(mid)) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
return ans;
}
int main() {
fastio
cin >> tc;
while (tc--) {
cin >> n >> c >> f;
p.assign(n, 0);
for (auto &i : p) cin >> i;
int ans = bs();
cout << ans << " $" << ans * f * c << "\n";
}
return 0;
}