The idea: normalize by half the total. A BIN-PACKING input is numbers in (0,1] and a bin count k, asking whether they fit into k bins each summing to ≤1. Divide each ai by half the total and all the numbers sum to exactly 2; then two bins of capacity 1 suffice iff an equal split exists.
The obstacle: some huge ai might exceed 1 after normalizing — an invalid output. But if 2ai>T there is no equal split at all, so in that case a fixed string outside the language can be returned.
Algorithm R′. On input (a1,…,an), natural numbers (w.l.o.g. ai>0; zeros may be dropped without changing the answer):
- Compute T←∑jaj.
- If some i has 2ai>T: return (43,43,43,2).
- Otherwise, for each i set bi←∑jaj2ai, and return (b1,…,bn,2).
The key property of the output. At step 3,
∑i=1nbi=∑iT2ai=T2∑iai=T2⋅T=2,
where pulling T2 out is legitimate because it is constant, independent of i. Also bi>0 and bi≤1 (since 2ai≤T at this step), so bi∈(0,1] and the output is valid.
On the representation. The bi are rationals held as a pair of integers — numerator 2ai, denominator T — each of length O(m+logn). A BIN-PACKING input need not be integral; the definition speaks of numbers in (0,1].