13529 - Twenty One - 2022midterm   

Description

After watching the movie 21, JN is curious about casino.

There are one banker and one guard in the casino. They have banker_ski and guard_ski skill respectively.

There are players playing twenty one. The i-th of them has mi dollars and skii skill.

 

There will be rounds of twenty one in total today.

In each round, each of the players place their bets beti first, then draw some cards.

The banker draws the cards last.

Let A be the sum of the i-th player's cards, B be the sum of the banker's.

Then:

  1. A > 21 and B > 21, nothing happens.
  2. A <= 21 and (B > 21 or A > B), the i-th player wins.
  3. B <= 21 and (A > 21 or B >= A), the i-th player loses.

 

For the banker:

  • If the i-th player wins, the banker has to pay beti dollars to the i-th player.
  • If the i-th player wins and skii < banker_ski, the banker has to pay the i-th player 10 * (the sum of the i-th player's cards) as a bonus.
  • Furthermore, if the i-th player wins and the sum of the i-th player's cards is equal to 21, the banker has to pay 2*(bets + bonus) to the i-th player. (bonus may be equal to 0)
  • For example, if the sum of the i-th player's cards is 21, skii < banker_ski, and beti = 1000, then the banker has to pay (1000+10*21)*2 to the i-th player.
  • Whenever a player becomes bankrupt, the banker calls the guard to kick the player out and gives the guard 100 dollars.
  • Whenever a player is seen to be a cheater; that is, 2*skii < the amount of money that the banker has to pay to the player, the banker calls the guard to kick the player out and gives the guard 100 dollars.

 

For the guard:

  • When the guard has to kick i-th player who is a cheater out, if guard_ski < skii, the guard has to pay (skii - guard_ski) dollars to the i-th player; if guard_ski >= skii, the guard doesn't have to pay.
  • When the guard has to kick a bankrupt player out, the guard doesn't have to pay.

 

For the player:

  • If the i-th player loses, the i-th player has to pay beti dollars to the banker.
  • If the i-th player loses but beti >= the amount of money the i-th player has now, the i-th player only has to pay all the money they have. In this case, the i-th player becomes bankrupt.
  • If the i-th player is already kicked out of the casino, ignore any of the i-th player's bets and cards.

 

The banker and the guard have 0 dollars at first.

 

You can use the following code to draw cards.

this->cards = 0;
string res = "";
while (res.size() <= 0)
    getline(cin, res);
stringstream ss(res);
while (ss >> res) {
    int temp = 0;
    for (int i = 0; i < (int)res.size(); ++ i)
        temp = temp * 10 + res[i] - '0';
    this->cards += temp;
}

Input

The first line of the input contains two numbers — guard_ski and banker_ski.

The second line of the input contains a number — the number of players.

Each of the next N lines contains a string namei and two numbers mi and skii — the name, money, and the skill the i-th player has.

The next line contains a number K — there will be K rounds of twenty two today.

The following contains blocks, i = 1, ..., N.

There will be a string namei and a number beti in the 2i - 1 line — the i-th player's name and the bets they place.

There will be some numbers c1, ..., ct in the 2i line — the cards the i-th player has.

The last line of each block will be some numbers c1, ..., ct — the cards the banker has.

 

N, K <= 500.

All the other numbers <= 5*104.

Output

You should print N+1 lines in total.

The first line of output should contains two numbers guard_money and banker_money — the money the guard and the banker gets.

Each of next N lines should contains a string namei and moneyi — the name of the i-th player and the money they have after playing.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13529.cpp

Partial Judge Header

13529.h

Tags




Discuss