This seems to be the matching problem for the [National Resident Matching Program][1] which is closely related to the [stable marriage problem][2].

In the resident matching problem your $C_i$ are medical students which have finished and need to apply to do residency. The $P_i$ are hospitals where they can train. Each hospital has some limit $p_i$ of people they can train.

Here is a [video][3] explaining the algorithm from the National Resident Matching Program.


  [1]: https://en.wikipedia.org/wiki/National_Resident_Matching_Program#Matching_algorithm
  [2]: https://en.wikipedia.org/wiki/Stable_marriage_problem
  [3]: https://www.nrmp.org/matching-algorithm/