Scoring stores

3

5 votes
2D dynamic programming, Algorithms, Dynamic Programming
Problem

A, B, and C are three friends. Their birth dates are in the ratio of 1:2:4. B forms a quadratic equation of the form ax2+bx+c, where the coefficient a,b, and c are the birth date ratios, that is, a=1, b=2, and c=4

C is preparing for a test, he gives n online tests and stores the score of these n tests in the form of an array. C wants to arrange the scores of these n tests in a non-decreasing order such that he can show it to his friends about his improvement. He uses the following operation to perform this task: 

  • Select one of the test marks and multiply it with the root of the quadratic equation provided by B.

Determine the minimum number of operations required to perform the task. 

Input format

  • First line: n denoting the number of test cases
  • Second line: n integers denoting the marks obtained in each test

Output format

Print a single integer that represents the minimum number of operations that can be performed to complete the task. If it is not possible, then print 1.

Constraints

1n2000001Ai1e9

Time Limit: 2
Memory Limit: 1024
Source Limit:
Explanation

Array after each ALPHA Operation would be:

ALPHA Operation 1: 3,1,4,−2

ALPHA Operation 2: −6,1,4,−2

ALPHA Operation 3: −6,1,4,4

Editor Image

?