Skip to content

Commit bd66953

Browse files
Create By Gamers For Gamers.cpp
1 parent cc820a8 commit bd66953

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
#define all(v) (v).begin(), (v).end()
6+
using namespace std;
7+
8+
int main()
9+
{
10+
int no_of_elements, max_cost;
11+
cin >> no_of_elements >> max_cost;
12+
13+
vector <long long> cost(no_of_elements + 1), damage(no_of_elements + 1), health(no_of_elements + 1);
14+
vector <long long> max_product(max_cost + 1, 0);
15+
for(int i = 1; i <= no_of_elements; i++)
16+
{
17+
cin >> cost[i] >> damage[i] >> health[i];
18+
19+
max_product[cost[i]] = max(max_product[cost[i]], damage[i]*health[i]);
20+
}
21+
22+
23+
for(int c = 1; c <= max_cost; c++)
24+
{
25+
for(int coin_sets = 1; c*1LL*coin_sets <= max_cost; coin_sets++)
26+
{
27+
max_product[c*coin_sets] = max(max_product[c*coin_sets], max_product[c]*coin_sets);
28+
}
29+
}
30+
31+
vector <long long> max_product_till(max_cost + 1);
32+
for(int i = 1; i <= max_cost; i++)
33+
{
34+
max_product_till[i] = max(max_product[i], max_product_till[i - 1]);
35+
}
36+
37+
int no_of_monsters;
38+
cin >> no_of_monsters;
39+
40+
for(int i = 1; i <= no_of_monsters; i++)
41+
{
42+
long long damage_here, health_here;
43+
cin >> damage_here >> health_here;
44+
45+
long long product = damage_here*health_here;
46+
47+
int minimum_coins = upper_bound(all(max_product_till), product) - max_product_till.begin();
48+
49+
cout << (minimum_coins <= max_cost ? minimum_coins : -1) << "\n";
50+
}
51+
52+
return 0;
53+
}
54+
55+

0 commit comments

Comments
 (0)