Created
April 13, 2013 00:38
-
-
Save fayimora/5376272 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object StoreCredit extends App | |
{ | |
val testCases = readInt | |
(1 to testCases).foreach{ tc => | |
val (c, i) = (readInt, readInt) | |
val prices = readLine.split(" +").map(_.toInt) | |
val res = solve(c, i, prices) | |
assert(res._1 > 0 && res._2 > 0) // sanity check | |
println("#Case %d: %d %d".format(tc, res._1, res._2)) | |
} | |
def solve(c: Int, numOfItems: Int, prices: Array[Int]): (Int, Int) = { | |
for(i <- 0 until numOfItems){ | |
for(j <- 0 until numOfItems){ | |
if(i!=j && (prices(i)+prices(j) == c)) return (i+1, j+1) | |
} | |
} | |
(-1,-1) // we really should never get here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment