In the context of a smart city operating a 5G and beyond network, we propose a mixed-integer linear programming model to optimize the placement of VNFs on a hybrid UAV-terrestrial infrastructure. This infrastructure is supported by UAVs that act as carriers for the VNFs. The aim is to maximize the lifetime of the UAVs while taking into account the resource constraints and network traffic generated by crowds gathering at specific locations in the city. To evaluate the effectiveness of our solution, we conduct experiments based on different practical scenarios. The results show that our proposed solution significantly improves the system's ability to handle incoming traffic in different scenarios.