Feb-10-2021, 11:55 AM
PROBLEM:
Joel has a collection of unique coins. He would like to use them to pay a certain amount of money, but he wouldn’t want to part with more than two of his coins for this purpose. Write a program which determines which amounts are possible to pay with exactly two of his coins.
You will get marks on this question depending on how efficient your program is. 3/5 is still a good score, as it’s not an easy question!
Input
The first line of the input contains 𝑛
n
, the number of coins in Joel’s collection.
Each of the following 𝑛
n
lines contain one number – the value in pence of a single coin.
The following line contains 𝑄
Q
, the number of questions. Note that 𝑄
Q
is at most 5.
Each of the final 𝑄
Q
lines contain one amount which Joel wants to pay.
Output
For each of the questions, output whether it is possible to pay the amount required using exactly two coins from Joel’s collection. Paying with one coin is boring and doesn’t count!
Output 𝑄
Q
lines, each containing YES or NO
--------------------------------------------------
WHAT I HAVE SO FAR:
Joel has a collection of unique coins. He would like to use them to pay a certain amount of money, but he wouldn’t want to part with more than two of his coins for this purpose. Write a program which determines which amounts are possible to pay with exactly two of his coins.
You will get marks on this question depending on how efficient your program is. 3/5 is still a good score, as it’s not an easy question!
Input
The first line of the input contains 𝑛
n
, the number of coins in Joel’s collection.
Each of the following 𝑛
n
lines contain one number – the value in pence of a single coin.
The following line contains 𝑄
Q
, the number of questions. Note that 𝑄
Q
is at most 5.
Each of the final 𝑄
Q
lines contain one amount which Joel wants to pay.
Output
For each of the questions, output whether it is possible to pay the amount required using exactly two coins from Joel’s collection. Paying with one coin is boring and doesn’t count!
Output 𝑄
Q
lines, each containing YES or NO
--------------------------------------------------
WHAT I HAVE SO FAR: