-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab_14.cpp
More file actions
59 lines (39 loc) · 1.21 KB
/
Copy pathLab_14.cpp
File metadata and controls
59 lines (39 loc) · 1.21 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
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
int minStepsToTargetSweetness(long long target_sweetness, const vector<long long>& candies) {
priority_queue<long long, vector<long long>, greater<long long>> min_heap;
for (long long sweetness : candies) {
min_heap.push(sweetness);
}
int steps = 0;
while (min_heap.top() < target_sweetness) {
if (min_heap.size() < 2) {
return -1;
}
long long C1 = min_heap.top();
min_heap.pop();
long long C2 = min_heap.top();
min_heap.pop();
long long C_new = C1 + 2 * C2;
min_heap.push(C_new);
steps++;
}
return steps;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long target;
if (!(cin >> target)) return 0;
vector<long long> candies;
long long sweetness;
while (cin >> sweetness) {
candies.push_back(sweetness);
}
cout << minStepsToTarge;
tSweetness(target, candies) << endl;
return 0;
}