The Problem
We are given N
number of tasks of N
days each. Each takes time t_i
to performed. Our job is to find out which combination of tasks minimizes the total amount of time taken. The constraint is that one task has to be performed every 3 days.
Sample Inputs/Outputs
Input 1
3 2 1 1 2 3 1 3 2 1
Output 1
4
Here the correct solution is t_3, t_4, t_7, t_10
Input 2
1 2 3 3 1 2 5 6 1
Output 2
6
Here the correct solution is t_3, t_6, t_9
My Thoughts
I believe this can be solved using dynamic programming
or a modification of the Continuous Knapsack Problem
. But I don't know how.
I thought of creating a graph starting with the first three tasks and having the next possible tasks as their children. Then to use the shortest path algorithm with weighted vertexes instead of weighted edges. But with values of N above even 1000, the memory limit of 32 MB
will be easily exceeded.
I'm kind of thinking that there should be a mathematically creative solution to this?
Question
What is the most efficient solution to this problem with the following limits?
1 ≤ N ≤ 2×10^5
The number of minutes of SUPW each day is between 0 and 10^4, inclusive.
Thanks.