n files, containing files from 1 to n. These files have to be stored in Amazon S3 buckets for backup. A total of K of these files are sensitive and require encryption. The sensitive files are given as an array sensitiveFiles.
The storage cost is determined as follows:
M files that contains X sensitive files, cost is M * X * encCost, where encCost is the encryption cost for sensitive files. This is applicable only when batch contains at least 1 sensitive file.M files with 0 sensitive files, the cost is a constant flatCost.M is divisible by 2 then:
2 equal parts and total cost will be the sum of the costs for smaller batches Note: When splitting a batch into two files, both must remain in their original order.
For example, given a batch containing files 1, 4, 2, 6, the only split is into {1, 4} and {2, 6}. You cannot reshuffle the files into different groupings like {1, 2} and {4, 6}. Though B1 can further be split into {1} and {4}, and similarly B2 can be split into {2} and {6}. You are to compute the minimum storage cost while maintaining the rules constraints.
Compute and return the minimum possible storage cost for the batch using the rules above.
long getMinimumStorageCost(int n, int encCost, int flatCost, int[] sensitiveFiles)
n: number of files in the batch (files are labeled from 1 to n)encCost: encryption cost multiplierflatCost: cost of storing a batch with 0 sensitive filessensitiveFiles: array containing the file numbers that are sensitivelong.Input
n = 4
encCost = 5
flatCost = 3
sensitiveFiles = []
Explanation
{1, 2, 3, 4} with X = 0 sensitive files.flatCost = 3 (rule 2).M = 4 is divisible by 2, you may split, but splitting into two batches with 0 sensitive files would cost 3 + 3 = 6, which is higher.3.Output
3
Input
n = 2
encCost = 2
flatCost = 1
sensitiveFiles = [1, 3]
Given
Batch = {1, 2, 3, 4}, where files 1 and 3 are sensitive.
Approach 1
4 with 2 sensitive files, using rule 1 gives cost: 4 * 2 * 2 = 16Approach 2
{1, 2} and {3, 4}{1, 2}: M = 2, X = 1
2 * 1 * 2 = 4{1} and {2}: {1} costs 1 * 1 * 2 = 2, {2} costs flatCost = 1, total 2 + 1 = 3{1, 2} is 3{3, 4}: similarly minimum cost is 33 + 3 = 6Output
6
Input
n = 2
encCost = 3
flatCost = 10
sensitiveFiles = [1, 2, 3, 4]
Explanation
{1, 2, 3, 4} has M = 4, X = 4.4 * 4 * 3 = 48.{1, 2} and {3, 4}: each has M = 2, X = 2, store whole cost 2 * 2 * 3 = 12, total 12 + 12 = 24.4M = 1, X = 1: cost 1 * 1 * 3 = 3 each, total 12, which is the minimum here.Output
12