using System; using System.Collections.Generic; using System.Linq; // https://yukicoder.me/problems/no/2561 class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("4 2"); WillReturn.Add("300 400 500 600"); } else if (InputPattern == "Input2") { WillReturn.Add("20 8"); WillReturn.Add("2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"); } else if (InputPattern == "Input3") { WillReturn.Add("8 8"); WillReturn.Add("812087642 562447828 487989038 879550309 409027146 501712355 131601217 18035145"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int[] wkArr = InputList[0].TrimEnd().Split(' ').Select(pX => int.Parse(pX)).ToArray(); int K = wkArr[1]; long[] AArr = InputList[1].TrimEnd().Split(' ').Select(pX => long.Parse(pX)).ToArray(); long Answer = 0; foreach (long[] EachArr in RubyPatternClass.Combination(AArr, K)) { long Sum1 = 0; long Sum2 = 0; foreach (long EachVal in EachArr) { Sum1 += EachVal; Sum2 += EachVal; Sum1 %= 998; Sum2 %= 998244353; } if (Sum1 >= Sum2) { Answer++; Answer %= 998; } } Console.WriteLine(Answer); } } #region RubyPatternClass // Rubyの場合の数 internal static class RubyPatternClass { // 組合せを返す private struct JyoutaiDef_Combination { internal int CurrP; internal List SelectedIndList; } internal static IEnumerable Combination(IEnumerable pEnum, int pR) { if (pR == 0) yield break; Type[] pArr = pEnum.ToArray(); if (pArr.Length < pR) yield break; var Stk = new Stack(); JyoutaiDef_Combination WillPush; for (int I = pArr.GetUpperBound(0); 0 <= I; I--) { WillPush.CurrP = I; WillPush.SelectedIndList = new List() { I }; Stk.Push(WillPush); } while (Stk.Count > 0) { JyoutaiDef_Combination Popped = Stk.Pop(); // クリア判定 if (Popped.SelectedIndList.Count == pR) { var WillReturn = new List(); Popped.SelectedIndList.ForEach(X => WillReturn.Add(pArr[X])); yield return WillReturn.ToArray(); continue; } for (int I = pArr.GetUpperBound(0); Popped.CurrP + 1 <= I; I--) { WillPush.CurrP = I; WillPush.SelectedIndList = new List(Popped.SelectedIndList) { I }; Stk.Push(WillPush); } } } } #endregion