Well if something good came of it it wouldn't be terrible now would it? The 'ends' should also include the means as the means have occurred and are therefore part of the end result. So if there was an action that was independently terrible yet the overall result was one of great goodness, then the terrible act would be part of the summative good, meaning the final result would be greatly good inclusive of the terrible bad that happened (meaning that, without the terrible bad the good would be so amazingly extreme that it would probably solve world hunger or something).
So sure, why not.