Scoring stores
Practice
3 (5 votes)
2d dynamic programming
Algorithms
Dynamic programming
Problem
51% Success 867 Attempts 30 Points 2s Time Limit 1024MB Memory 1024 KB Max Code

\(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 \(ax^2+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

\(1 \le n \le 200000\\ 1 \le A_i \le 1e^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
23 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMediumOpenRecursionTreesTwo dimensional
Points:30
4 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMediumOpen
Points:30
24 votes
Tags:
AlgorithmsDynamic ProgrammingDynamic programming