-
Notifications
You must be signed in to change notification settings - Fork 0
/
aust judge 06dec2018 F.cpp
102 lines (95 loc) · 2 KB
/
aust judge 06dec2018 F.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include<bits/stdc++.h>
using namespace std;
const int sz = 110;
struct ingredient
{
int x;
int y;
int sm;
int pm;
int sv;
int pv;
int shortage;
int reqexpenditure;
};
typedef struct ingredient ingredient;
bool compare(ingredient a, ingredient b)
{
return a.reqexpenditure < b.reqexpenditure;
}
ingredient arr[sz];
int ans;
int a, b;
int n, m;
int mncost;
int lim1, lim2;
double getRatio(double a, double b)
{
return a/b;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(int i=0; i<n; i++)
{
cin >> arr[i].x;
cin >> arr[i].y;
cin >> arr[i].sm;
cin >> arr[i].pm;
cin >> arr[i].sv;
cin >> arr[i].pv;
if(arr[i].y >= arr[i].x)
arr[i].shortage = 0;
else
arr[i].shortage = arr[i].x-arr[i].y;
arr[i].reqexpenditure = numeric_limits<int>::max();
a = arr[i].sv;
b = arr[i].sm;
lim1 = arr[i].shortage/a;
lim2 = arr[i].shortage/b;
mncost = arr[i].reqexpenditure;
for(int x=0, y=0; x<=lim1; x++)
{
if(a*x >= arr[i].shortage)
{
if(arr[i].pv*x <= m)
{
mncost = min(mncost, arr[i].pv*x);
}
//break;
}
else
{
y = ceil(getRatio(arr[i].shortage-a*x, b));
if(arr[i].pm*y <= m)
{
mncost = min(mncost, arr[i].pv*x+arr[i].pm*y);
}
}
}
arr[i].reqexpenditure = mncost;
}
sort(arr, arr+n, compare);
for(int i=0; i<n && m>0; i++)
{
if(arr[i].shortage==0)
{
ans++;
continue;
}
/////
if(arr[i].reqexpenditure <= m)
{
m -= mncost;
ans++;
}
else
{
//break;
}
}
cout << ans << "\n";
return 0;
}