Question
Arman is a hardworking Nazarbayev University student who studies every day so that he does not fall behind in CSCI 270. For every day, his
Arman is a hardworking Nazarbayev University student who studies every day so that he does not fall behind in CSCI 270. For every day, his performance is measured by an integer number. You are given a sequence of n days (n is an integer) and an array of n integers P[1], P[2], ... p[n], where p[i] represents Arman's performance for day . We say that there is a drop in Arman's performance between day j and day k if j < k and P[k] < P[j]. The amount of drop is P[j] p[k]. Find the minimum amount of drop across the n days. (All numbers in the array P[] are distinct. There is always a valid nonzero answer.)
Input format: Line 1: Integer n Line 2: Integers P[1], p[2], .,p[n]
Output format: An integer that represents the minimum amount of drop in Arman's performance
Sample input: 5 20 78 25
Sample output: 2
Explanation: The drop in performance between day 1 and day 2 is 20-7=13 The drop in performance between day 2 and day 4 is 7-2=5
There is no drop in performance between 3 (because P[3] > p[2]) The drop in performance between day 1 and day 5 is 7-5-2 and this is the minimum drop across the five days.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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