Minimizing TotalWeighted Error for Imprecise Computation Tasks and Related Problems