## Problem Description and Formulation

The company wants to maximize the audience reach of its TV commercials given a weekly budget of $50,000. The commercials can be run during movies, sports games, or comedy shows, each with different costs and expected audience reaches. The constraints are:

- The cost for a commercial during movies is $1000 with 25,000 viewers.
- The cost for a commercial during sports games is $5000 with 100,000 viewers, and there can be at most 5 commercials.
- The cost for a commercial during comedy shows is $2000 with 45,000 viewers.
- At most a third of all commercials should occur during comedy shows.
- A minimum of 15% of all commercials should occur during movies.
- The weekly budget is $50,000.

## Decision Variables

Let \(M\), \(S\), and \(C\) be the number of commercials run during movies, sports games, and comedy shows, respectively.

## Objective Function

Maximize the total audience reach: \(25,000M + 100,000S + 45,000C\).

## Constraints

1. Budget constraint: \(1000M + 5000S + 2000C \leq 50,000\)
2. Sports games constraint: \(S \leq 5\)
3. Comedy shows constraint: \(C \leq \frac{1}{3}(M + S + C)\)
4. Movies constraint: \(M \geq 0.15(M + S + C)\)
5. Non-negativity constraint: \(M, S, C \geq 0\) and are integers.

## Gurobi Code

```python
import gurobipy as gp
from gurobipy import GRB

# Create a new model
model = gp.Model("TV_Commercial_Optimization")

# Decision variables
M = model.addVar(lb=0, vtype=GRB.INTEGER, name="Movies")
S = model.addVar(lb=0, vtype=GRB.INTEGER, name="Sports")
C = model.addVar(lb=0, vtype=GRB.INTEGER, name="Comedy")

# Objective function: Maximize audience reach
model.setObjective(25000*M + 100000*S + 45000*C, GRB.MAXIMIZE)

# Budget constraint
model.addConstr(1000*M + 5000*S + 2000*C <= 50000, name="Budget")

# Sports games constraint
model.addConstr(S <= 5, name="Sports_Limit")

# Comedy shows constraint
model.addConstr(C <= (M + S + C)/3, name="Comedy_Limit")

# Movies constraint
model.addConstr(M >= 0.15*(M + S + C), name="Movie_Minimum")

# Solve the model
model.optimize()

# Print the results
if model.status == GRB.OPTIMAL:
    print("Optimal Solution:")
    print(f"Movies: {M.varValue}")
    print(f"Sports: {S.varValue}")
    print(f"Comedy: {C.varValue}")
    print(f"Objective: {model.objVal}")
else:
    print("No optimal solution found.")
```