Mobile Edge Computing (MEC) extends Cloud Computing to the edge of the network, creating a hierarchy of data centers. This paradigm provides computing capacity close to final users, relieves backhaul and the leading network, and serves latency-sensitive applications. When providing computing services at different network levels, it becomes necessary to carry out a more efficient distribution of the resources that come to coexist. A random allocation of these resources can lead to a low service acceptance rate and backhaul overhead problems. Problems like these can be solved with MEC. To maximize the service acceptance and ensure a fair distribution of services in the kinds of servers guaranteeing their QoS requirements, we propose a MILP (Mixed Integer Linear Programming). The model performs an optimal allocation of applications in a two-level hierarchy of data centers: (i) MEC and (ii) cloud computing. On a large scale, the use of MILP becomes unfeasible due to the high computational cost, so we propose a heuristic based on the application profiles. We compare the proposed heuristic with two metaheuristics: (i) Genetic Algorithm and (ii) Particle Swarm Optimization. The solutions are compared in terms of service acceptance rate, largescale performance, and efficient use of available resources. Results show that the proposed heuristic reaches 91% of the optimal solution and over 140% compared to AG and PSO solutions.