#C1582. Mission Points Accumulation

    ID: 44803 Type: Default 1000ms 256MiB

Mission Points Accumulation

Mission Points Accumulation

You are given a set of missions and a sequence of player actions. Each mission is defined by an identifier and an associated point value. Each player action consists of a player ID, a mission ID, and a success flag indicating whether the player successfully completed the mission.

Your task is to simulate the progression of players through these missions and compute the total points accumulated by each player, considering only the successful actions. Formally, for each player, compute:

\[ \text{Total Points} = \sum_{\substack{\text{action is successful}}} p_{mission} \]

where \(p_{mission}\) represents the points associated with the respective mission.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer \(m\), representing the number of missions.
  • The next \(m\) lines each contain two integers: the mission identifier and the mission's point value.
  • The following line contains an integer \(n\), representing the number of player actions.
  • The next \(n\) lines each contain three values: the player identifier, the mission identifier, and a success flag (where 1 indicates success and 0 indicates failure).

outputFormat

For each player that appears in the actions, output a single line containing two integers: the player's ID and their total accumulated points, separated by a space. The players should be listed in ascending order of their IDs. The output is written to standard output (stdout).

## sample
4
1 100
2 50
3 25
4 75
6
101 1 1
101 2 0
102 4 1
101 3 1
102 2 1
101 4 0
101 125

102 125

</p>