Codechef Problems: Red and Blue Gems (REDBLUEGEM)
Problem Statement:
Solution:
Given,
R : number of red gems
B : number of blue gems
P : price of red gem
Q : price of blue gem
condition: it is not allowed to buy both color of gems
To find, maximum coins obtained by selling gems
condition 1 : price of red gems > price of blue gems
here price of red gems = R * P
price of blue gems = B * Q
if price of red gems is greater than price of blue gems then we can get more coins by selling red gems
output : R * P
condition 2 : price of blue gems > price of red gems
we can get more coins by selling blue gems
so output : B * Q
Code Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, b, p, q;
cin >> r >> b >> p >> q;
if (r * p >= b * q) {
cout << r * p << endl;
} else {
cout << b * q << endl;
}
return 0;
}
Comments
Post a Comment