-
-
Save akhilesh-kumar-verma/fdf1c1d0ea4a7a0c7a8ea6b3bf775342 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool possible(unsigned long long n_b, unsigned long long n_s, unsigned long long n_c, | |
unsigned long long p_b, unsigned long long p_s, unsigned long long p_c, | |
unsigned long long r_b, unsigned long long r_s, unsigned long long r_c, | |
unsigned long long r, unsigned long long m) { return (m*r_b-n_b)*p_b+(m*r_s-n_s)*p_s+(m*r_c-n_c)*p_c<=r; } | |
int main() { | |
string reciepe; cin >> reciepe; | |
unsigned long long n_b, n_s, n_c; cin >> n_b >> n_s >> n_c; | |
unsigned long long p_b, p_s, p_c; cin >> p_b >> p_s >> p_c; | |
unsigned long long r; cin >> r; | |
unsigned long long r_b=count(reciepe.begin(), reciepe.end(), 'B'), | |
r_s=count(reciepe.begin(), reciepe.end(), 'S'), | |
r_c=count(reciepe.begin(), reciepe.end(), 'C'); | |
unsigned long long soln; | |
for (unsigned long long low=0, high=1e15; low < high;) { | |
#define MID (low+(high-low)/2) | |
if (possible(n_b, n_s, n_c, p_b, p_s, p_c, r_b, r_s, r_c, r, MID)) { | |
soln=MID; low=MID+1; } | |
else { high=MID-1; } } | |
#undef MID | |
cout << soln << endl; | |
return 0; } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment