Treasure Hunt CodeChef Code-O-Fiesta solution Python

Treasure Hunt Editorial and Solutions

PROBLEM STATEMENT

YOU CAN FIND THE COMPLETE PROBLEM STATEMENT HERE :PROBLEM STATEMENT

Two friends Ron and Harry went to take part in a game called treasure hunt. There are N levels in the game. In each level ‘i’, Ci numbers of coins of the same value are hidden. Ron is happy if he has strictly more coins than Harry. However, Harry is happy only if the difference between their number of coins is not more than 1. They agree to help each other by collecting the coins in such a way that makes both of them happy. Write a code to output “YES” if there is a possibility of both of them being happy after playing the game; otherwise output “NO”.

UNDERSTANDING THE PROBLEM:

So the problem is pretty straight forward, we take the input of the number of coins in each level as a comma separated string then we see if its possible to get the coins distributed between the friends such that both friends are happy . In other words the total number of coins of all games should be in the form x (the loser) + x+1 ( the winner) in other words It should be of the form 2x+1. Note that all odd numbers are in the form 2x+1 so it would not be possible for both the friends to be happy if the coins including all games are equal.

PYTHON 3 CODE:

Now that we know the logic behind the code lets implement it. It is a very easy problem!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
n =int(input())
a = input()
lst = a.split(" ")
sum =0
for item in lst:
	sum+=int(item)
if sum%2 == 0:
	print("NO")
else:
	print("YES")

Comments