Home / Expert Answers / Computer Science / need-your-help-to-solve-this-problem-using-python-all-my-attempts-exceed-the-memory-limit-please-co-pa451

(Solved): need your help to solve this problem using python. all my attempts exceed the memory limit!please co ...



need your help to solve this problem using python. all my attempts exceed the memory limit!
please consider using space proportional to input size, rather than the largest input number.
with correct outputs please. 


D. Feeding Friendsy
time limit per test: \( 2.5 \) seconds \( \theta \)
memory limit per test: 256 megabytes
input: standard
Mario always did better than any of the other players in this game. Now he wants to make sure that he can beat anybody. In or
Note
For \( 25 \% \) of the test cases, \( 0 \leq T \leq 10^{4}, 0 \leq n \leq 10^{3}, 0 \leq m \leq 10^{3} \).
For \( 100 \%
D. Feeding Friendsy time limit per test: \( 2.5 \) seconds \( \theta \) memory limit per test: 256 megabytes input: standard input output: standard output Throw the balls into the open mouths! Making a shot when the mouth is glowing is worth extra! (80 points) Feeding Friendsy is a 4-player minigame in Super Mario Party, and you can view how the game is actually played here. The rules are rather simple. As shown below, there are two Cheep Chomp (the two big mouthed fish) mechs, which will open their mouths during certain time intervals. Each player will throw balls into the mouths of the Cheep Chomps and if they go into the open mouths, they get points. When the open mouth appears normal like the top Cheep Chomp, each goal is worth one point. If the mouth is glowing with an arcing rainbow like the bottom Cheep Chomp, each goal is worth three points. Every player can throw at most one ball at one unit of time, either to the upper or the lower Cheep Chomp. Mario always did better than any of the other players in this game. Now he wants to make sure that he can beat anybody. In order to improve, he recorded the gameplay and watched it to find out the best strategy. The duration of each game is \( T \) units of time (from time 0 to time \( T-1 \) ). Given all the time periods that each Cheep Chomp has its mouth open, and the information about whether they are normal or rainbow, we want to know the maximum points one can earn within \( T \). units of time. Input The first line of the input contains three integers, \( T, n \), and \( m \) that represent the duration of the game, the number of time intervals that the upper Cheep Chomp opens its mouth, and the number of time intervals that the lower Cheep Chomp opens its mouth respectively. The next \( n \) lines each contain a tuple \( a, b, c(0 \leq a \leq b \leq T-1, c \in\{0,1\}) \). which means that the upper Cheep Chomp opens its mouth from time \( a \) to time \( b \) (inclusive). If \( c=0 \), that means its mouth is open normally (so each goal is 1 ) point). When \( c=1 \), it means that the mouth is open with rainbow glowing (so each goal is 3 point. These \( n \) time intervals do not overlap with each other, and are sorted by time. The next \( m \) lines each also contain a tuple \( a, b, c(0 \leq a \leq b \leq T-1 \), \( c \in\{0,1\} \), which means that the lower Cheep Chomp opens its mouth from fime \( a \) to time \( b \) (inclusive), Similarly \( c=0 \) means normal and \( c=1 \) means rainbow. These \( m \) time intervals do not overlap with each other, and are sorted by time. (Note that this problem is different from the "Feeding Friendsy" problem in the practice contest. The problem size is much larger than the practice version.) Output The output only contains one integer, which is the highest possible score that Note For \( 25 \% \) of the test cases, \( 0 \leq T \leq 10^{4}, 0 \leq n \leq 10^{3}, 0 \leq m \leq 10^{3} \). For \( 100 \% \) test cases, \( 0 \leq T \leq 10^{8}, 0 \leq n \leq 10^{6}, 0 \leq m \leq 10^{6} \). Hint: Just reading the input can take long. If you use C++, you could try "scanf" instead of cin. For Java you could use "Scanner". Here's an example of one of the best solutions for the first sample input/output: \( \times \) means that Mario threw the ball to that mouth at that time. So the maximum number of points he earns is \( 1+1+3+3+1+1+1+1=12 \) points.


We have an Answer from Expert

View Expert Answer

Expert Answer


The must be similar to this code as i was not able to code it properly, sorry my code is :- def feeding_friendsy(T, n, m, upper, lower): # upper and l
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe