Dynamical theory of the inverted cheerios effect