```go
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
type Station struct {
x, p int
}
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var d, n, m int
fmt.Fscan(reader, &d, &n, &m)
stations := make([]Station, m)
for i := 0; i < m; i++ {
fmt.Fscan(reader, &stations[i].x, &stations[i].p)
}
// Sort stations by position
sort.Slice(stations, func(i, j int) bool {
return stations[i].x < stations[j].x
})
// Add the district center as a virtual station with 0 cost
stations = append(stations, Station{x: d, p: 0})
// Check if the first station is reachable from start (position 0)
if stations[0].x > n {
fmt.Fprintln(writer, -1)
return
}
// Precompute the next station with a strictly lower price
// The destination (index m) has price 0, guaranteeing a lower price exists for all real stations
nextCheaper := make([]int, m+1)
stack := make([]int, 0, m+1)
for i := 0; i <= m; i++ {
for len(stack) > 0 && stations[stack[len(stack)-1]].p > stations[i].p {
idx := stack[len(stack)-1]
stack = stack[:len(stack)-1]
nextCheaper[idx] = i
}
stack = append(stack, i)
}
// Initial state after driving to the first station
currentFuel := int64(n - stations[0].x)
totalCost := int64(0)
curr := 0
for curr < m {
next := nextCheaper[curr]
distToNextCheaper := int64(stations[next].x - stations[curr].x)
if distToNextCheaper <= int64(n) {
// Case A: Can reach a cheaper station (or destination)
// Buy just enough to get there
if currentFuel < distToNextCheaper {
needed := distToNextCheaper - currentFuel
totalCost += needed * int64(stations[curr].p)
currentFuel = 0
} else {
currentFuel -= distToNextCheaper
}
curr = next
} else {
// Case B: Cannot reach a cheaper station
// Fill tank full at current station (cheapest in range) and move to next immediate station
distToImmediate := int64(stations[curr+1].x - stations[curr].x)
if distToImmediate > int64(n) {
fmt.Fprintln(writer, -1)
return
}
add := int64(n) - currentFuel
totalCost += add * int64(stations[curr].p)
currentFuel = int64(n) - distToImmediate
curr++
}
}
fmt.Fprintln(writer, totalCost)
}
```