In a heap model, solid blocks, or pieces, pile up according to the Tetris game mechanism. An optimal schedule is an in nite sequence of pieces minimizing the asymptotic growth rate of the heap. In a heap model with two pieces, we prove that there always exists an optimal schedule which is balanced, either periodic or Sturmian. We also consider the model where the successive pieces are chosen at random, independently and with some given probabilities. We study the expected growth rate of the heap. For a model with two pieces, the rate is either computed explicitly or given as an in nite series. We show an application for a system of two processes sharing a resource, and we prove that a greedy schedule is not always optimal. Key words: Optimal scheduling, timed Petri net, heap of pieces, Tetris game, (max,+) semiring, automaton with multiplicities, Sturmian word.