using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("2 1 1"); WillReturn.Add("CCGP"); //12 } else if (InputPattern == "Input2") { WillReturn.Add("0 0 5"); WillReturn.Add("CCCCC"); //0 } else if (InputPattern == "Input3") { WillReturn.Add("7 6 5"); WillReturn.Add("GCPGPCPGGGPCCCGPGP"); //50 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray(); int CardCntG = wkArr[0]; int CardCntC = wkArr[1]; int CardCntP = wkArr[2]; char[] SArr = InputList[1].ToCharArray(); int AiteCntG = SArr.Count(X => X == 'G'); int AiteCntC = SArr.Count(X => X == 'C'); int AiteCntP = SArr.Count(X => X == 'P'); int Score = 0; //勝てるカードを全て割当 Score += ExecWariate(ref CardCntG, ref AiteCntC) * 3; Score += ExecWariate(ref CardCntC, ref AiteCntP) * 3; Score += ExecWariate(ref CardCntP, ref AiteCntG) * 3; //あいこになるカードを全て割当 Score += ExecWariate(ref CardCntG, ref AiteCntG); Score += ExecWariate(ref CardCntC, ref AiteCntC); Score += ExecWariate(ref CardCntP, ref AiteCntP); Console.WriteLine(Score); } //貪欲法で、カードを割当し、割当枚数を返す static int ExecWariate(ref int pCardCnt, ref int pAiteCnt) { int WillReturn; //全て割当可能の場合 if (pCardCnt <= pAiteCnt) { WillReturn = pCardCnt; pAiteCnt -= pCardCnt; pCardCnt = 0; return WillReturn; } //一部割当可能の場合 WillReturn = pAiteCnt; pCardCnt -= pAiteCnt; pAiteCnt = 0; return WillReturn; } }