← Home
 ```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var f, T, t0 int64
	fmt.Fscan(in, &f, &T, &t0)

	var a1, t1, p1 int64
	fmt.Fscan(in, &a1, &t1, &p1)

	var a2, t2, p2 int64
	fmt.Fscan(in, &a2, &t2, &p2)

	if f*t0 <= T {
		fmt.Fprintln(out, 0)
		return
	}

	const INF int64 = 1<<60
	ans := INF

	solve := func(f, T, t0, a1, t1, p1, a2, t2, p2 int64) {
		var maxX int64
		if t1 >= t0 {
			maxX = 0
		} else {
			maxX = f / a1
		}

		for x := int64(0); x <= maxX; x++ {
			bytes1 := x * a1
			time1 := bytes1 * t1
			if time1 > T {
				break
			}
			cost1 := x * p1
			remBytes := f - bytes1
			remTime := T - time1

			if remBytes*t0 <= remTime {
				if cost1 < ans {
					ans = cost1
				}
				continue
			}

			if t2 >= t0 {
				continue
			}

			deficit := remBytes*t0 - remTime
			savePerPkg2 := a2 * (t0 - t2)
			y := (deficit + savePerPkg2 - 1) / savePerPkg2

			if y*a2 <= remBytes {
				totalCost := cost1 + y*p2
				if totalCost < ans {
					ans = totalCost
				}
			}
		}
	}

	solve(f, T, t0, a1, t1, p1, a2, t2, p2)
	solve(f, T, t0, a2, t2, p2, a1, t1, p1)

	if ans == INF {
		fmt.Fprintln(out, -1)
	} else {
		fmt.Fprintln(out, ans)
	}
}
```