Problem · Array
Maximum Decrypted Score
Learn this problemProblem statement
You are given two arrays of equal length: scores and decryptionStatus. The value scores[i] is the sensitivity score of file i.
The value decryptionStatus[i] describes the current state of file i:
1means the file is already decrypted.0means the file is still encrypted.
You may perform the following operation at most once: choose a contiguous subarray containing at most k files and decrypt every file in that subarray.
Return the maximum possible sum of the scores of all decrypted files after the optional operation.
Function
maximumDecryptedScore(scores: int[], decryptionStatus: int[], k: int) → longExamples
Example 1
scores = [7,4,3,5]decryptionStatus = [1,0,0,0]k = 2return = 15The already decrypted first file contributes 7. Choosing indices [2,3] decrypts files with scores 3 and 5, producing 7 + 3 + 5 = 15, which is greater than the totals from the other length-two segments.
Constraints
1 <= scores.length <= 10^3decryptionStatus.length == scores.length0 <= scores[i] <= 10^9decryptionStatus[i]is either0or1.1 <= k <= scores.length