# PROBLEM LINK: Contest Page | CodeChef

[Practice] (Contest Page | CodeChef)

*Author:* Varghese Babu

*Tester:* Varghese Babu

*Editorialist:* Varghese Babu

DIFFICULTY : INTERMEDIATE

# PREREQUISITES:

BASIC MATH

# PROBLEM:

A blacksmith and his apprentice decides to relocate from his current location to next town. But the town is too far off and cannot carry all of his goods at once. So he decides to sell all his excess amount of weopons in a 50% discounted price. The blacksmith and apprentice has ‘x’ and ‘y’ amount of storage and sword and axe requires ‘m’ and ‘n’ space each. Find the number of weopons(swords and axes separate) he has to give a discounted price and sell of for if he is to move to the next town carrying the maximum number of weopons Also find the number of weopons he can carry?

Assumptions

Assume that the if both sword and axe have equal space requirement the priority is given for sword Assume that minimum number of weopon of each type in the store is 1 Assume if the weopon with lesser space requirement is given priority

# EXPLANATION:

Since the problem is to find the maximum weopons carried => we have to utilise the most space with the weopon with the least space requirement. Also, the blacksmith and apprentice carries weopons separatly therefore we have to calculate this separately too. Another thing to be cared about is the total no of weopons, if the maximum carriable amount of weopons is greater than total no of that weopon available then we have to use the maximum weopon count of that particular weopon available.

divide the total weopons in blacksmith by smallest weopon space requirment and store it as the no of weopon carriable by blacksmith

check if that no is less than total amount of that weopon

if yes add reduce the space in blacksmith and reduce the no of total weopon

else use the total weopon for the same and reduce the no of total weopon to 0 and reduce the space from the blacksmith

update the no of weopons carried

repeat the same for apprentice with the small weopon

Do the same whole process for the weopon with higher space requirement

# SOLUTIONS:

## Setter's Solution

def calcSpace(spaceReq, totSpace, totWeopons):

maxWeoponCarriable = totSpace[0] // spaceReq

if(maxWeoponCarriable <= totWeopons):

noOfWeoponsB = maxWeoponCarriable

else:

noOfWeoponsB = totWeopons

totWeopons = totWeopons - noOfWeoponsB

totSpace[0] = totSpace[0] - noOfWeoponsB * spaceReq

maxWeoponCarriable = totSpace[1] // spaceReq

if(maxWeoponCarriable <= totWeopons):

noOfWeoponsA = maxWeoponCarriable

else:

noOfWeoponsA = totWeopons

totWeopons = totWeopons - noOfWeoponsA

totSpace[1] = totSpace[1] - noOfWeoponsA * spaceReq

return noOfWeoponsB + noOfWeoponsA

totWeopons = [int(x) for x in input().split()]

totSpace = [int(x) for x in input().split()]

weoponSpaceReq = [int(x) for x in input().split()]

if(weoponSpaceReq[0] <= weoponSpaceReq[1]):

swordsCarried = calcSpace(weoponSpaceReq[0], totSpace, totWeopons[0])

axesCarried = calcSpace(weoponSpaceReq[1], totSpace, totWeopons[1])

else:

axesCarried = calcSpace(weoponSpaceReq[1], totSpace, totWeopons[1])

swordsCarried = calcSpace(weoponSpaceReq[0], totSpace, totWeopons[0])

print("{} {}".format(totWeopons[0] - swordsCarried , totWeopons[1] - axesCarried))

print("{} {}".format(swordsCarried, axesCarried))

## Tester's Solution

Same Person

## Editorialist's Solution

Same Person