using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("800 200 100"); WillReturn.Add("1 2 2 1"); //2 } else if (InputPattern == "Input2") { WillReturn.Add("800 1200 1200"); WillReturn.Add("300 300 300 300"); //0 } else if (InputPattern == "Input3") { WillReturn.Add("800 800 800"); WillReturn.Add("1 1 1 0"); //1 } else if (InputPattern == "Input4") { WillReturn.Add("314159265 9 26"); WillReturn.Add("17781089 21082123 14498465 7071840"); //18908650 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static long[] GetSplitArr(string pStr) { return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray(); } static long mR; static long mP; static long mQ; static long mRedCnt; static long mYeloowCnt; static long mBlueCnt; static long mGreenCnt; static void Main() { List InputList = GetInputList(); long[] wkArr = GetSplitArr(InputList[0]); mR = wkArr[0]; mP = wkArr[1]; mQ = wkArr[2]; wkArr = GetSplitArr(InputList[1]); mRedCnt = wkArr[0]; mYeloowCnt = wkArr[1]; mBlueCnt = wkArr[2]; mGreenCnt = wkArr[3]; long L = 0; long R = (mRedCnt + mYeloowCnt + mBlueCnt + mGreenCnt)+100; //bool Res = CanAchieve(2); //Console.WriteLine(Res); //return; while (L + 1 < R) { long Mid = (L + R) / 2; bool Result = CanAchieve(Mid); //Console.WriteLine("CanAchieve({0})={1}", Mid, Result); if (Result) { L = Mid; } else { R = Mid; } } Console.WriteLine(L); } // X人のルーマニア人を作れるかを返す static bool CanAchieve(long pX) { if (pX == 0) return true; long RestRate = mR - mP * pX; if (RestRate < 0) return false; long RestChangeCnt = RestRate / mQ; // 交換要因 long ChangeMan = mGreenCnt; if (mRedCnt > pX) ChangeMan += mRedCnt - pX; if (mYeloowCnt > pX) ChangeMan += mYeloowCnt - pX; if (mBlueCnt > pX) ChangeMan += mBlueCnt - pX; if (mRedCnt < pX) { RestChangeCnt -= pX - mRedCnt; ChangeMan -= pX - mRedCnt; } if (mYeloowCnt < pX) { RestChangeCnt -= pX - mYeloowCnt; ChangeMan -= pX - mYeloowCnt; } if (mBlueCnt < pX) { RestChangeCnt -= pX - mBlueCnt; ChangeMan -= pX - mBlueCnt; } if (RestChangeCnt < 0) return false; if (ChangeMan < 0) return false; return true; } }