-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Cutting.cpp
More file actions
62 lines (51 loc) · 1.12 KB
/
B_Cutting.cpp
File metadata and controls
62 lines (51 loc) · 1.12 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstring>
using ll = long long;
using ull = unsigned long long;
using lld = long double;
#define GREETINGS_FROM_LOS_POCATOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
int main()
{
GREETINGS_FROM_LOS_POCATOS
int n, B;
cin >> n >> B;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> cutCosts;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 0) even++;
else odd++;
if (i != n - 1 && odd == even) {
cutCosts.push_back(abs(a[i+1] - a[i]));
}
}
sort(cutCosts.begin(), cutCosts.end());
int cuts = 0;
int totalCost = 0;
for (int cost : cutCosts) {
if (totalCost + cost <= B) {
totalCost += cost;
cuts++;
} else {
break;
}
}
cout << cuts << endl;
return 0;
}