Answered step by step
Verified Expert Solution
Question
1 Approved Answer
He has n watermelons and each one has a specific index denote as a. The watermelons are store in a cylindrical() box. Osas wants
He has n watermelons and each one has a specific index denote as a. The watermelons are store in a cylindrical() box. Osas wants to eat a watermelon indexed a;. But if the watermelon indexed a; is not on the top, he needs to eat all watermelon above the watermelon indexed a;. For example if the index of watermelon from top to bottom is: 5, 3, 2, 1, 4. And Osas wants to eat watermelon which index is 2, then he need to eat watermelons which index are 5, 3, 2 at the same time. Osas has a list which is the order of index of watermelons he wants to eat which denoted as b. The length of the list is also n and all b; are distinct. Please help him calculate that each time he wants to eat a watermelon, how many watermelons he needs to eat at same time? For example if the index of watermelon from top to bottom is: 5, 3, 2, 1, 4. And the list Osas has is: 2, 3, 4, 5, 1. First time Osas will eat 3 watermelons(5,3,2). Second time because the watermelons that indexed 3 is already been eaten, Osas eat 0 watermelon. So on and so forth. In this example, you need to output: 3 0 2 0 0. Input input contains three lines. First line contains n the number of watermelons.( 1 Sample Input Download 5 53214 23451 Sample Output Download 30200
Step by Step Solution
★★★★★
3.47 Rating (170 Votes )
There are 3 Steps involved in it
Step: 1
Time Compexity ON Space Complexity ON include include int main int n scanfd n int inputListn int ind...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started