Use cost instead of size for a constraint on random memories.