-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF-Buy-A-String-v2.cpp
More file actions
56 lines (42 loc) · 1.16 KB
/
Copy pathCF-Buy-A-String-v2.cpp
File metadata and controls
56 lines (42 loc) · 1.16 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
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int minCoinsToBuy (int LN,int C0,int C1,int CH,string S) {
int minCoinstoBuy;
int curCostOfString = int(
(std::count(S.begin(), S.end(), '0')*C0) +
(std::count(S.begin(), S.end(), '1')*C1)
);
int minCoin = min(C0,C1);
int minCost = LN*minCoin;
minCoinstoBuy = curCostOfString;
if ( minCost < curCostOfString )
{
if ( C0 > C1)
{
if (abs(C0-C1)-CH > 0) {
minCoinstoBuy = (std::count(S.begin(), S.end(), '0')*CH)+
(LN*C1);
}
}
else
{
if (abs(C0-C1)-CH > 0) {
minCoinstoBuy = (std::count(S.begin(), S.end(), '1')*CH)+
(LN*C0);
}
}
}
return minCoinstoBuy;
}
int main() {
string S;
int num_of_test_cases = 0;
int LN,C0,C1,CH;
cin >> num_of_test_cases;
for (int ictr=1;ictr<=num_of_test_cases;ictr++) {
cin >> LN >> C0 >> C1 >> CH;
cin >> S;
cout << minCoinsToBuy(LN,C0,C1,CH,S) << endl;
}
}