-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbuying.cpp
More file actions
43 lines (35 loc) · 1009 Bytes
/
cbuying.cpp
File metadata and controls
43 lines (35 loc) · 1009 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
#include <iostream>
#include <algorithm>
using namespace std;
struct input{
long long cost;
long long amount;
};
bool inputcomp(input a, input b){
return a.cost<b.cost;
}
int main(){
long long cows, money, counter=0;
cin >> cows >> money;
input chocolate[cows];
for(int i=0; i<cows; i++){
cin >> chocolate[i].cost >> chocolate[i].amount;
}
sort(chocolate, chocolate+cows, inputcomp);
// for(int i=0; i<cows; i++){
// cout << chocolate[i].cost << " " << chocolate[i].amount << endl;
// }
for(int i=0; i<cows; i++){
long long maxamount = money/chocolate[i].cost;
if(maxamount>chocolate[i].amount) maxamount=chocolate[i].amount;
counter+=maxamount;
long long subtract=maxamount*chocolate[i].cost;
money-=subtract;
if(money<=0 or chocolate[i].cost>money){
cout << counter << endl;
return 0;
}
}
cout << counter << endl;
return 0;
}