Problems with solving tasks (please help) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problems with solving tasks (please help)

Hello, I can't solve two problems. Can somebody help me? Here is what the first one looks like: Peter loves muffins. He decides to buy some for himself and decides to choose from three different muffins. Help Peter buy as much muffins as he can with the money he's got. Input: on the first line are the prices of the three muffins. On the second line is the number of muffins of each type. On the third line is the money Peter has. ex. Input: 5 3 8 2 6 4 23 Output: 7 The second one looks like this: Three cars ride on the same road and cover the same distance. They start and finish at different times. Find the shortest and the longest time to cover the distance. Input: on the first line is the starting time and the arrival time of the first car. On the second line is the starting time and the arrival time of the second car. On the third line is the starting time of the third car (in hour and minutes). Output: On the first line is the shortest time in hours and minutest. On the second line is the longest time which took to cover the distance (the time format should be hh : mm). ex. Input: 23 30 1 30 2 5 5 15 15 5 20 53 Output: 2:00 5:48

7th Mar 2020, 8:48 AM
Betina
Betina - avatar
7 Answers
+ 1
Betina One way is take values in Arrays and sort.. When swapping prices with indexes, at same swap corresponding muffin numbers. Got it? Edit: { temp=P[i]; P[i]=p[i+1]; P[i+1]=temp; temp=M[i] ; M[i] =M[i+1]; M[i+1]=temp; } //P price, M muffins...
7th Mar 2020, 9:31 AM
Jayakrishna 🇮🇳
0
I think in the first one the code thinks this way. It needs to return the maximum number of muffins Peter can buy. Which means it doesn't necessarily have to buy a single muffin from all categories. So it buys 6 3$ muffins as there only 6.then there's 5$ left. If it was 7 it will buy 7 3$ muffins. And for the remaining 5$ it'll buy a 5$ muffin which makes it total of 7
7th Mar 2020, 8:57 AM
Naveen K R
0
Betina actually what do you need help with ?
7th Mar 2020, 8:58 AM
Naveen K R
0
1st, : sort prices and select least prices muffins.. 3*6+5*1=23 6+1=7 2nd : abs( ending time - starting time)
7th Mar 2020, 9:02 AM
Jayakrishna 🇮🇳
0
Jayakrishna but I can’t sort the prices and then the muffins because the position of all the elements is important and if I do that, I wouldn’t know how to arrange the muffins on the second line.
7th Mar 2020, 9:12 AM
Betina
Betina - avatar
0
Naveen K R I couldn’t figure out how to start the counting from 0 when the time is 24:00 and for the muffins I couldn’t figure out how to sort the elements on both lines without changing the price of a current muffin.
7th Mar 2020, 9:15 AM
Betina
Betina - avatar
0
Betina about the muffins problem can you tell me how you want the program to work? If you wanted the maximum number of muffins Pete can buy you got the correct answer.
7th Mar 2020, 10:35 AM
Naveen K R