<p>I use int.MaxValue as a penalty and sometimes I am computing the penalties together. Is there a function or how would you create one with the most grace and efficiency that does that. </p>

<p>ie. </p>

<p>50 + 100 = 150</p>

<p>int.Max + 50 = int.Max and not int.Min + 50 </p>

```
```
int penaltySum(int a, int b)
{
    return (int.MaxValue - a < b) ? int.MaxValue : a + b;
}
```
```
Update: If your penalties can be negative, this would be more appropriate:
```
```
int penaltySum(int a, int b)
{
    if (a > 0 && b > 0)
    {
        return (int.MaxValue - a < b) ? int.MaxValue : a + b;
    }

    if (a < 0 && b < 0)
    {
        return (int.MinValue - a > b) ? int.MinValue : a + b;
    }

    return a + b;
}
```
```