The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 5 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
James Moriarty started fire at M places in London. Sherlock Holmes has been called to help extinguish the fires as quickly as possible. There are exactly N fire stations in the city, each having infinite amount of fire trucks. But the time taken by each fire station to fill a truck is different and the fire stations can only fill one truck at a time. Initially all the fire trucks are empty.
Given the time taken by each fire station to fill one truck and the time taken for a fire truck to reach the jthplace from the ith fire station, Sherlock needs to tell the minimum time taken to extinguish the fire at all places.
First line contains T,(T
Each line of first test case contains two integers N and M,(N,M
Next line contains N space separated integers, where the ith integer denotes the time taken (1th fire station to fill one truck.
Then next N lines will follow, each containing M integers, where the integer at ith row and jth column denotes the time taken (1th fire station to reach jth place.
Output of each test case is a single line denoting the minimum time required to extinguish the fire completely.
Consider that as soon as a fire truck reaches the place, the fire extinguishes there in no time.
Each place will require exactly one truck to extinguish the fire.
Fire truck once used can not be used again.
There are infinite number of fire trucks at every station.
Input: 1 3 4 2 5 4 1 2 3 1 2 3 1 2 2 2 3 1 Output: 6
The 1st fire station sends trucks to both 1st and 4th place. Time Taken=5
The 2nd fire station sends a truck to 3rd place. Time Taken=6
The 3rd fire station sends a truck to 2nd place. Time Taken=6
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll