Editorial
For tourist, the time spent on problem is included in the completion times of problems . Therefore, tourist's penalty is
For rainboy, is included in the completion times of problems , so rainboy's penalty is
Thus, the required difference is
It can be computed in one pass over the array. The time complexity is .
Solution written by GPT5.6