// unit-time scheduling with penalties // see CLR, p. 350-353 #include #include typedef struct tableEntry tableType; struct tableEntry { int deadline,penalty; }; tableType inputTable[500],schedule[500],late[500]; int numTasks,lateTasks=0; int penaltySort(x,y) tableType *x,*y; { return y->penalty - x->penalty; } main() { int i,j,totalPenalty=0; scanf("%d",&numTasks); for (i=0;i=0 && schedule[j].deadline>=inputTable[i].deadline; j--) schedule[j+1]=schedule[j]; schedule[j+1]=inputTable[i]; } else { for (j=inputTable[i].deadline-1; j=0 && schedule[j].deadline>inputTable[i].deadline;j--) schedule[j+1]=schedule[j]; schedule[j+1]=inputTable[i]; } printf("Schedule is:\n"); for (j=0;j