My personal opinion: the task is utopian - since the answer tends to n.
Conditionality of the decision:
based on the data we have, after each conversation with a friend, we will update the persuasion queues:
- first of all those who have lower authority than Tolik will get, and b> 0,
- secondarily, those with higher authority than Tolik will get, and b> 0,
- in the third place, those who have lower authority than Tolik will get, and b <0,
- in the fourth place will be those with higher authority than Tolik, and b <0,
- separate list of those who have b = 0
Conventionally: "lower" and "less" include equality with the compared value.
We will add to the list of invitees those who agreed and exclude from the queues.
We also agree that b is an integer; it is necessary for a complete depiction of the picture of the second stage of the solution.
The solution of the problem:
Stage 1:
Due to the democratic nature of the task ( if the author complicates, it will be more interesting ), at the very beginning we give in to persuasion of all the people from the first stage, thereby raising our authority, we will be able to drag some from the second stage to the first.
We persuade those who have b = 0, add them to the list of successfully promoted. Having reached the maximum of authority, we will compile a list of hopeless ones from the remnants of the second and fourth queues.
Stage 2:
We have: the third turn and lists of invited and hopeless.
Sort by ascending module b.
Gradually losing credibility, we invite the first in the sorted list of the third queue (based on the accepted condition, b = (- 1)). We update queues. Increase the module b. If b is equal (the value is already negative), suppose that there are two such (Z and Y), for simplicity, we get the system:
Za ? Yb + b ? Ta Ya ? Za + b ? Ta
The system considers the following questions: is it possible for Tolik (Ta) to invite Z first and then Y, or vice versa, choose the option in which we invite the maximum quantity, that is, two, this particular sequence is the key one. Do not forget about updating the queues, and rebuilding the system after that.
Stage 3
Preparing of report
Podstchet successfully promoted, and formatting the file according to the condition of the problem.
Something like this.