Optimization of third-order discrete and differential inclusions described by polyhedral set-valued mappings