Suppose we partition the elements of an array b into any number k of non-empty subarrays S1,S2,…,Sk , where k is an arbitrary positive integer. Define the score of b as the maximum value of MEX(S1)+MEX(S2)+…+MEX(Sk) over all possible partitions of b for any integer k n <= 2e5
continous subarrays not for subsequence for [0 0 1 1] ans is 3
how can i calculate score .
Auto comment: topic has been updated by kavascg (previous revision, new revision, compare).
I misread the problem
how would u implement it? like how would you make partition i can think of an O(n^2) approach and ans for [ 0 1 2 3 6 5 4 3 2 1 0 0] will be 12
The solution is:
Make a frequency table, store the frequency of all elements in the array, make a prefix (min) array of that frequency table, the answer is the sum of all elements in the prefix min array.
A nice problem that uses the same idea : 2030E - MEXimize the Score
this would be for subsquence for subarray it would be diff [0 0 1 1 ] will have ans 3
This looks like DP where dp[i] is the score of the prefix until i but I didn't solve yet
Auto comment: topic has been updated by kavascg (previous revision, new revision, compare).
Auto comment: topic has been updated by kavascg (previous revision, new revision, compare).