Skip to content

Instantly share code, notes, and snippets.

@fayimora
Created April 13, 2013 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fayimora/5376272 to your computer and use it in GitHub Desktop.
Save fayimora/5376272 to your computer and use it in GitHub Desktop.
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