Closest Cow Wins algorithm

I have a method in mind to calculate for each interval between the i_th cow and the i+1_th cow the maximum taste acquired if 1 and 2 cows are placed in the interval. Then, I can use a modified Knapsack to find the maximum taste. However, after coding a few lines, I have realised that there may be duplications as every patch is included in 2 intervals. I’d like to know if this method will work and the specific approach. Thanks in advance!