-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path028.Minimum_types.cpp
42 lines (40 loc) · 1.18 KB
/
028.Minimum_types.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
//Minimum types - codechef(1394)
/*
As we need to find the minimum types of coins used, we will first take a vector which stores the total sum of each ith coin in ith place.
we will sort it it descending order.
at ending we will keep element 0, if the sum of all coins doesn't sufficient then we will print -1.
we will run a loop by checking condition that if the sum is greater than or equal to x(given).
*/
//https://www.codechef.com/problems/MINBUY
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int j = 0; j < n; j++) {
cin >> b[j];
}
vector <int> v;
for (int i = 0; i < n; i++) {
v.push_back(a[i]*b[i]);
}
sort(v.begin(), v.end(), greater<int>());
v.push_back(0);
int sum = v[0],i;
for ( i = 1; i < n+1; i++) {
if (sum >= x) {
break;
}
sum += v[i];
}
if (i == n+1) cout << -1 <<endl;
else cout << i << endl;
}
}