本场比赛其他题目题解
A. Regular Bracket Sequences
B. Combinatorics Homework
C. Slay the Dragon
D. The Strongest Build
C. Slay the Dragon
题目描述
Recently, Petya learned about a new game “Slay the Dragon”. As the name suggests, the player will have to fight with dragons. To defeat
a dragon, you have to kill it and defend your castle. To do this, the player has a squad of n n n heroes, the strength of the i i i-th hero is equal to a i a_i ai.
According to the rules of the game, exactly one hero should go kill the dragon, all the others will defend the castle. If the dragon’s defense is equal to x x x, then you have to send a hero with a strength of at least x x x to kill it. If the dragon’s attack power is y y y, then the total strength of the heroes defending the castle should be at least y y y.
The player can increase the strength of any hero by 1 1 1 for one gold coin. This operation can be done any number of times.
There are m m m dragons in the game, the i i i-th of them has defense equal to x i x_i xi and attack power equal to y i y_i yi. Petya was wondering what is the minimum number of coins he needs to spend to defeat the i i i-th dragon.
Note that the task is solved independently for each dragon (improvements are not saved).
Input
The first line contains a single integer n n n ( 2 ≤ n ≤ 2 ⋅ 1 0 5 2\le n\le 2⋅10^5 2≤n≤2⋅10