Don't use cplex.sum
inside addTerm
. You just need to separate out the two terms in your Objective function, since they both are summed over k.
Minimize sum (trueck[k] - time[k]) for all k (1..n)
Is the same as Min *sum_over_k* (trueck[k]) - *sum_over_k* (time[k])
This way, addTerm can handle it. (The code below is untested, but it gives you the idea of what you should try.)
IloLinearNumExpr obj = cplex.linearNumExpr();
for(int k=0; k<grossK.length; k++){
obj.addTerm(1.0, trueck[k]);
obj.addTerm(-1.0, time[k]);
}
cplex.addMinimize(obj);
Hope that helps.