Allocating tasks and resources