-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1049.cpp
More file actions
48 lines (37 loc) · 724 Bytes
/
1049.cpp
File metadata and controls
48 lines (37 loc) · 724 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, M, cost, sum;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M;
vector<int> package(M);
vector<int> item(M);
for(int i = 0; i < M; i++){
cin >> package[i] >> item[i];
}
sort(package.begin(), package.end());
sort(item.begin(), item.end());
if(N < 6){
cout << min(package[0], item[0] * N);
return 0;
}
while(1){
if(sum >= N) break;
if(N - sum < 6){
cost += min(package[0], item[0] * (N - sum));
break;
}
if(package[0] <= item[0] * 6){
sum += 6;
cost += package[0];
}
else{
sum += 6;
cost += item[0] * 6;
}
}
cout << cost << '\n';
return 0;
}