Minimum operations
Practice
3 (113 votes)
Arrays
Data structures
1 D
C++
Problem
74% Success 12790 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of length \(N\) and can perform the following operation on the array:
- Select a subarray from array \(A\) having the same value of elements and decrease the value of all the elements in that subarray by any positive integer \(x\).
Find the minimum number of operations required to make all the elements of array \(A\) equal to zero.
Input format
- The first line contains an integer \(N\) denoting the number of elements in the array.
- The next line contains space-separated integers denoting the elements of array \(A\).
Output format
Print the minimum number of operations required to make all the elements of array \(A\) equal to zero.
Constraints
\(1 \le N \le 5 \times 10^5 \\ 1 \le A[i] \le 10^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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
337 votes
Tags:
1-D arrayArraysData Structures
Points:10
25 votes
Tags:
ArraysData Structures1-D
Points:10
869 votes
Tags:
Ad-HocApprovedData StructuresEasyOne-dimensional
Editorial
Login to unlock the editorial