-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_1049.cpp
More file actions
59 lines (52 loc) · 1.26 KB
/
BOJ_1049.cpp
File metadata and controls
59 lines (52 loc) · 1.26 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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct GuitarString {
int packagePrice;
int onePrice;
};
int n, m;
int findMinPackagePrice(vector<GuitarString> brands) {
int minPrice = 987654321;
for (auto ptr = brands.begin(); ptr != brands.end(); ptr++) {
if (ptr->packagePrice < minPrice)
minPrice = ptr->packagePrice;
}
return minPrice;
}
int findMinOnePrice(vector<GuitarString> brands) {
int minPrice = 987654321;
for (auto ptr = brands.begin(); ptr != brands.end(); ptr++) {
if (ptr->onePrice < minPrice)
minPrice = ptr->onePrice;
}
return minPrice;
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
int totalCost = 0;
cin >> n >> m;
vector<GuitarString> brands;
for (int i = 0; i < m; i++) {
GuitarString gs;
cin >> gs.packagePrice >> gs.onePrice;
brands.push_back(gs);
}
int minPackagePrice = findMinPackagePrice(brands);
int minOnePrice = findMinOnePrice(brands);
while (n > 0) {
if (n >= 6) {
int _cost = min(minPackagePrice, minOnePrice * 6);
totalCost += (_cost * (n / 6));
n %= 6;
} else {
int _cost = min(minPackagePrice, minOnePrice * n);
totalCost += _cost;
break;
}
}
cout << totalCost;
return 0;
}