You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: 1705.Maximum Number of Eaten Apples.go
    path of file: ./repos/LeetCode-Go/leetcode/1705.Maximum-Number-of-Eaten-Apples
    
    the code of the file until where you have to start completion: package leetcode

import "container/heap"

func eatenApples(
    
func eatenApples(apples []int, days []int) int {
	h := hp{}
	i := 0
	var ans int
	for ; i < len(apples); i++ {
		for len(h) > 0 && h[0].end <= i {
			heap.Pop(&h)
		}
		if apples[i] > 0 {
			heap.Push(&h, data{apples[i], i + days[i]})
		}
		if len(h) > 0 {
			minData := heap.Pop(&h).(data)
			ans++
			if minData.left > 1 {
				heap.Push(&h, data{minData.left - 1, minData.end})
			}
		}
	}
	for len(h) > 0 {
		for len(h) > 0 && h[0].end <= i {
			heap.Pop(&h)
		}
		if len(h) == 0 {
			break
		}
		minData := heap.Pop(&h).(data)
		nums := min(minData.left, minData.end-i)
		ans += nums
		i += nums
	}
	return ans
}