#include #include //sort d but does not modify d; it writes the sorted indices in output void sort(int *d, int *output, int n) { int i,j; for(i=0; id[output[j]]) { output[i]=output[i]^output[j]; output[j]=output[i]^output[j]; output[i]=output[i]^output[j]; } } void schedule_guess(int* l, int* d, int n) { int i, late=0, *schedule,time,flag=1; schedule = (int*)malloc(n*sizeof(int)); sort(d, schedule, n); for(;flag;late++) { time=0; flag=0; for(i=0;id[schedule[i]]+late) late = time+l[schedule[i]]-d[schedule[i]]; time+=l[schedule[i]]; } printf("Optimal schedule by greedy algorithm is: "); for(i=0;i