2분 검색 Codeforces Round #218(Div.2) C. Hamburgers

6724 단어 codeforces

제목 전송문
 1 /*  2    :            ,        ,             ,           3    :      ,                  4 */  5 #include <cstdio>  6 #include <algorithm>  7 #include <cmath>  8 using namespace std;  9 10 typedef long long ll; 11 const int MAXN = 1e2 + 10; 12 const int INF = 0x3f3f3f3f; 13 char ham[MAXN]; 14 ll nb, ns, nc; 15 ll pb, ps, pc; 16 ll b, s, c; 17 ll m; 18 19 bool check(ll x) { 20 ll cost = 0; 21 if (b * x > nb) cost += (b * x - nb) * pb; 22 if (s * x > ns) cost += (s * x - ns) * ps; 23 if (c * x > nc) cost += (c * x - nc) * pc; 24 return cost <= m; 25 } 26 27 int main(void) { //Codeforces Round #218 (Div. 2) C. Hamburgers 28 scanf ("%s", &ham); 29 scanf ("%I64d%I64d%I64d", &nb, &ns, &nc); 30 scanf ("%I64d%I64d%I64d", &pb, &ps, &pc); 31 scanf ("%I64d", &m); 32 b = s = c = 0; 33 for (int i=0; ham[i]; ++i) { 34 if (ham[i] == 'B') b++; 35 else if (ham[i] == 'S') s++; 36 else c++; 37  } 38 ll l = 0, r = 1e13; 39 while (l + 1 < r) { 40 ll mid = (l + r) >> 1; 41 if (check (mid)) l = mid; 42 else r = mid; 43  } 44 printf ("%I64d
", l); 45 46 return 0; 47 }

좋은 웹페이지 즐겨찾기