NPLFLB - Editorial

PROBLEM LINK:

Practice

Contest

Author: Harsh Shah

Tester: Aniket Marlapalle

Editorialist: Aniket Marlapalle

DIFFICULTY:

easy

PREREQUISITES:

basic-programming

PROBLEM:

There are n players in the game with an initial energy of Ai. The game continues for d days with one of following incidents happening on each day.

  • One of the players gains an energy of X
  • Two of these players fight with each other and player with lower energy loses. Thus the winner gets all the energy and loser's energy becomes 0.
After each day you need to tell the maximum amount of energy that any player has.

EXPLANATION:

We can maintain the current energy of all the players in an array. Also maintain a global maximum energy amount. Because the player with maximum energy never loses, his energy will not be decreased by any of the 2 queries so it always increases so just update the global maximum value after every query.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here

//