Cops and the Thief Devu Solution

 Cops and the Thief Devu

There are 100 houses located on a straight line. The first house is numbered 1 and the last one is numbered 100. Some M houses out of these 100 are occupied by cops.

Thief Devu has just stolen PeePee's bag and is looking for a house to hide in.

PeePee uses fast 4G Internet and sends the message to all the cops that a thief named Devu has just stolen her bag and ran into some house.

Devu knows that the cops run at a maximum speed of x houses per minute in a straight line and they will search for a maximum of y minutes. Devu wants to know how many houses are safe for him to escape from the cops. Help him in getting this information.

Input Format

First line of input contains 3 space separated integers: Mx and y.

The second line contains M space separated integers which represent the house numbers where the cops are residing.

Output Format

Output a single line containing the number of houses which are safe to hide from cops.

Constraints

  • 1 ≤ x, y, M ≤ 10

Sample Test Cases:

Input1:

4 7 8

12 52 56 8

Output1:

0

Explanation1:

 Based on the speed, each cop can cover 56 houses on each side. These houses are:

  • Cop in house 12 can cover houses 1 to 11 if he travels left and houses 13 to 68 if he travels right. Thus, this cop can cover houses numbered 1 to 68.
  • Cop in house 52 can cover houses 1 to 51 if he travels left and houses 53 to 100 if he travels right. Thus, this cop can cover houses numbered 1 to 100.
  • Cop in house 56 can cover houses 1 to 55 if he travels left and houses 57 to 100 if he travels right. Thus, this cop can cover houses numbered 1 to 100.
  • Cop in house 8 can cover houses 1 to 7 if he travels left and houses 9 to 64 if he travels right. Thus, this cop can cover houses numbered 1 to 64.

Thus, there is no house which is not covered by any of the cops.

 

Input2:

2 10 2

21 75

Output2:

18

Explanation2:

Based on the speed, each cop can cover 20 houses on each side. These houses are:

  • Cop in house 21 can cover houses 1 to 20 if he travels left and houses 22 to 41 if he travels right. Thus, this cop can cover houses numbered 1 to 41.
  • Cop in house 75 can cover houses 55 to 74 if he travels left and houses 76 to 95 if he travels right. Thus, this cop can cover houses numbered 55 to 95.

Thus, the safe houses are house number 42 to 54 and 96 to 100. There are 18 safe houses.

SAMPLE INPUT
 
4 7 8
12 52 56 8
SAMPLE OUTPUT
 
0







Program:

m, x, y = map(int, input().split())
c = list(map(int, input().split()))
s = 0
for i in range(1, 101):
safe = True
for j in range(m):
if abs(i - c[j]) <= x*y:
safe = False
break
if safe:
s += 1
print(s)




Explanation:

               This is a Python code that reads in three values m, x, and y from standard input, followed by a list of m integers c. Then, it calculates the number of integers between 1 and 100 (inclusive) that are "safe" given the values of x, y, and c, and prints the result.

            The code starts by initializing a variable s to 0, which will be used to keep track of the number of safe integers. Then, it iterates over all integers between 1 and 100 (inclusive) using

Post a Comment

0 Comments