Editorial for DMOPC '18 Contest 6 P4 - Tank
Submitting an official solution before solving the problem yourself is a bannable offence.
Sort the physical and magical attacks by their value and compute a prefix sum for each one. For each unit, we can binary search the attacks to determine how many attacks are completely negated due to their defense/resistance, as well as the total of the attacks which are not negated using the prefix sum. Then we can compute the total damage for each unit by subtracting their defense/resistance multiplied by the number of non-negated attacks from the total of the attacks not completely negated.