Fix broken demand calculation

Felipe Cerqueira reported incorrect QPA results. The root cause was
a corner case in the demand calculation. This patch fixes the
underestimation of demand if time == deadline and adds a test case
discovered by Felipe that triggered the bug.