Creative Accounting
InterviewTime limit5sMemory limit1024 MB
Given daily profits and a range of segment sizes, find the minimum and maximum count of profitable segments over all sizes and starting days.
- Level
Medium4 of 10
- Topics
- Prefix sum, Brute force, Array
- Solved
- No attempts yet
Problem
When accounting for the profit of a business, we can divide consecutive days into fixed-size segments and calculate each segment's profit as the sum of all its daily profits. For example, we could choose seven-day segments to do our accounting in terms of weekly profit. We also have the flexibility of choosing a segment's starting day. For example, for weekly profit we can start a week on a Sunday, Monday, or even Wednesday. Choosing different segment starting days may sometimes change how the profit looks on the books, making it more (or less) attractive to investors.
As an example, we can divide ten consecutive days of profit (or loss, which we denote as negative profit) into three-day segments as such:
This gives us four segments with profit . For the purpose of this division, partial segments with fewer than the fixed segment size are allowed at the beginning and at the end. We say a segment is profitable if it has a strictly positive profit. In the above example, only two out of the four segments are profitable.
If we try a different starting day, we can obtain:
This gives us four segments with profit . All four segments are profitable, which makes our business look much more consistent.
You are given a list of consecutive days of profit, as well as an integer range. If we can choose any segment size within that range and any starting day for our accounting, what is the minimum and maximum number of profitable segments that we can have?
Input
The first line of input has three space-separated integers , and (, ), where is the number of days in the books, is the minimum possible choice of segment size, and is the maximum possible choice of segment size.
Each of the next lines contains a single integer (). These are the daily profits, in order.
Output
Output on a single line two space-separated integers and , where is the minimum number of profitable segments possible, and is the maximum number of profitable segments possible. Both and are taken over all possible choices of segment size between and and all possible choices of starting day.