Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	scanner.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()
	p := nextInt()

	priceA := a * p
	priceB := 0
	if p <= c {
		priceB = b
	} else {
		priceB = b + (p-c)*d
	}
	fmt.Println(min(priceA, priceB))
}

C++: #include <iostream>

using namespace std;

int main()
{
  int p;
  int a,b,c,d;
  int x,y;
  int over;

  cin >> a >> b >> c >> d >> p;

  x = p*a;


  if(p <= c)
    {
      y = b;
    }
  else
    {
      over = p-c;
      y = b+over*d;
    }

  if(x <= y)
    {
      cout << x << endl;
    }
  else
    {
      cout << y << endl;
    }
}