Food Subscription
Practice
4 (1 votes)
Easy
Problem
81% Success 2871 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

You want to buy a food subscription package for the upcoming month. You know exactly the days on which you will eat. This month has 30 days and there are 3 types of packages that available :

  • 1-Day Package - 199 valid for one day.
  • 7-Day Package - 699 valid for 7 consecutive days.
  • 30-Day Package - 2499 valid for all 30 days of the month.

You want to pay as little as possible. You will be given a sorted (in increasing order) array A of dates when you will be eating. For example, given:
\(A[0] = 1 ,A[1] = 2, A[2] = 4, A[3] = 5, A[4] = 7, A[5] = 29, A[6] = 30 \)

You can buy 7-Day and 1-day subscription. The two 1-day subscriptions should be used on days 29 and 30. The 7-day subscription should be used on the first seven days of the month. The total cost is 1097 and there is no other possible way of paying less.

Write a function:

function solution (A) { } that, given an array \(A\) consisting of \(N\) integers that specifies days on which you will eat, returns the minimum amount of money that you have to spend on food subscription for the month.

Input Format
An array \(A\) of \(N\) days where you would be eating.

Output Format
The minimum amount of money that you have to spend.

Constraints

  • \(N\) is an integer within the range \([0..30]\);
  • Each element of array \(A\)is an integer within the range \([1..30]\)
  • Array \(A\) is sorted in increasing order
  • The element of \(A\) is all distinct.

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
16 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMediumOpen
Points:30
4 votes
Tags:
Data StructuresFenwick treeMedium
Points:30
15 votes
Tags:
Data StructuresEasyMathOne-dimensionalSets
Editorial

No editorial available for this problem.