static void Main(string[] args) { int dataSets = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < dataSets; i++) { int money = Convert.ToInt32(Console.ReadLine()); int flavors = Convert.ToInt32(Console.ReadLine()); string[] dataAsStrings = Console.ReadLine().Split(' '); int[] dataAsInts = Array.ConvertAll(dataAsStrings, Int32.Parse); List <IceCreamNode> icNodes = new List <IceCreamNode>(); for (int j = 0; j < dataAsInts.Length; j++) { IceCreamNode icNode = new IceCreamNode(dataAsInts[j], j + 1); icNodes.Add(icNode); } icNodes.Sort(); for (int k = 0; k < dataAsInts.Length; k++) { int icCost = dataAsInts[k]; int needed = money - icCost; int foundID = BinarySearchSolution.binarySearchRecursive(icNodes, needed, 0, icNodes.Count - 1); if ((foundID > 0) && (foundID != (k + 1))) { Console.WriteLine("{0} {1}", k + 1, foundID); break; } } } }
public int CompareTo(object obj) { IceCreamNode icNode = obj as IceCreamNode; if (icNode == null) { throw new ArgumentException("Object is not an IceCreamNode."); } if (this.price < icNode.price) { return(-1); } else if (this.price == icNode.price) { return(0); } else { return(1); } }