Let,
Number of battles on th day
Number of wins of th fighter on th day
Number of defeated battle of th fighter on th day
So, amount of money, a bettor can win by betting on th day
Here, we can calculate by counting the number of inversions of th element of the given array which can be found by Binary Indexed Tree or Segment Tree while iterating from the th element to the st element of the array. We can use the coordinate compression technique to compress the array values so that the array values become smaller.
Now, the maximum amount of money can be found by using dynamic programming.
We have to run a of size where is the maximum amount of money after days and total bets are done previously.
As, a bettor has to bet on exactly days in a row, on each day there are exactly options do not bet and go to the next day or bet on th and th day and go to th day as go to th day is forbidden if a bettor bets on th day. So, the transition of states will be as below.
Complexity:
[Note: The th element and the th element forms an inversion if and . The number of inversions of the th element is the count of all for which the th element and the th element forms an inversion.]