A - 荷物の仕分け 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 233 点

問題文

高橋君は配送センターで荷物の仕分け作業を担当しています。このセンターでは、届いた荷物を配送予定の年月ごとに振り分けて管理しています。

今月は Y 年 M 月です。高橋君のもとに N 個の荷物が届きました。i 番目 (1 \leq i \leq N) の荷物には、受付年月 A_i 年 B_i 月、配送予定年月 P_i 年 Q_i 月、重量 C_i グラムが記載されています。

高橋君は、これらの荷物のうち配送予定年月が今月のものと翌月のものをそれぞれ振り分け、各月の合計重量を求めたいと考えています。なお、受付年月は荷物に記載されていますが、振り分けには一切使用しません。

ここで、ある年月の翌月とは次のように定めます。

  • その月が 12 月の場合、翌月は翌年の 1 月とする。例えば 2025 年 12 月の翌月は 2026 年 1 月である。
  • それ以外の場合、翌月はその年の次の月とする。例えば 2025 年 3 月の翌月は 2025 年 4 月である。

振り分けルールは次の通りです。

  • 配送予定年月 P_i 年 Q_i 月が Y 年 M 月と一致する荷物は、今月分とする。
  • 配送予定年月 P_i 年 Q_i 月が Y 年 M 月の翌月(上記の定義に従う)と一致する荷物は、翌月分とする。
  • 上記のいずれにも該当しない荷物は無視する(合計重量に加えない)。

今月分の合計重量と翌月分の合計重量をそれぞれ求めてください。該当する荷物が 1 つもない月の合計重量は 0 とします。

制約

  • 1 \leq N \leq 100
  • 2000 \leq Y \leq 2100
  • 1 \leq M \leq 12
  • 2000 \leq A_i \leq 2100 (1 \leq i \leq N)
  • 1 \leq B_i \leq 12 (1 \leq i \leq N)
  • 2000 \leq P_i \leq 2100 (1 \leq i \leq N)
  • 1 \leq Q_i \leq 12 (1 \leq i \leq N)
  • 配送予定年月 P_i 年 Q_i 月は、受付年月 A_i 年 B_i 月と同じか、その翌月(上記の定義に従う)のいずれかである。(1 \leq i \leq N)
  • 1 \leq C_i \leq 10000 (1 \leq i \leq N)
  • 入力はすべて整数である。

入力

N Y M
A_1 B_1 P_1 Q_1 C_1
A_2 B_2 P_2 Q_2 C_2
\vdots
A_N B_N P_N Q_N C_N
  • 1 行目には、荷物の個数 N 、今月の年 Y 、今月の月 M が、スペース区切りで与えられる。
  • 続く N 行のうち i 行目 (1 \leq i \leq N) には、i 番目の荷物の受付年 A_i 、受付月 B_i 、配送予定年 P_i 、配送予定月 Q_i 、重量 C_i が、スペース区切りで与えられる。

出力

今月分の合計重量と翌月分の合計重量を、スペース区切りで 1 行に出力せよ。該当する荷物が 1 つもない月の合計重量は 0 とすること。末尾に改行を出力すること。


入力例 1

3 2025 3
2025 3 2025 3 500
2025 3 2025 4 300
2025 2 2025 2 1000

出力例 1

500 300

入力例 2

4 2025 6
2025 1 2025 1 200
2025 1 2025 2 300
2025 3 2025 3 400
2025 3 2025 4 500

出力例 2

0 0

入力例 3

10 2025 12
2025 12 2025 12 100
2025 12 2026 1 200
2025 11 2025 12 300
2025 11 2025 11 150
2025 12 2026 1 400
2026 1 2026 1 500
2026 1 2026 2 250
2025 10 2025 10 600
2025 10 2025 11 700
2025 12 2025 12 350

出力例 3

750 1100

入力例 4

20 2050 7
2050 7 2050 7 100
2050 7 2050 8 200
2050 6 2050 7 300
2050 6 2050 6 400
2050 7 2050 8 500
2050 8 2050 8 150
2050 8 2050 9 250
2050 7 2050 7 350
2050 5 2050 5 1000
2050 5 2050 6 2000
2050 7 2050 8 700
2050 6 2050 7 800
2050 7 2050 7 450
2050 8 2050 8 300
2050 9 2050 9 600
2050 7 2050 8 900
2050 6 2050 6 550
2050 6 2050 7 650
2050 8 2050 8 120
2050 7 2050 7 210

出力例 4

2860 2870

入力例 5

1 2000 1
2000 1 2000 1 1

出力例 5

1 0

Score : 233 pts

Problem Statement

Takahashi is in charge of sorting packages at a delivery center. At this center, incoming packages are sorted and managed by their scheduled delivery year and month.

The current month is year Y, month M. Takahashi has received N packages. The i-th package (1 \leq i \leq N) has the following information: reception year-month A_i year B_i month, scheduled delivery year-month P_i year Q_i month, and weight C_i grams.

Takahashi wants to sort these packages into those whose scheduled delivery year-month is the current month and those whose scheduled delivery year-month is the next month, and calculate the total weight for each month. Note that although the reception year-month is written on the packages, it is not used for sorting at all.

The next month of a given year-month is defined as follows:

  • If the month is December (12), the next month is January (1) of the following year. For example, the next month of December 2025 is January 2026.
  • Otherwise, the next month is the next month of the same year. For example, the next month of March 2025 is April 2025.

The sorting rules are as follows:

  • If the scheduled delivery year-month P_i year Q_i month matches year Y month M, the package is classified as this month's.
  • If the scheduled delivery year-month P_i year Q_i month matches the next month of year Y month M (according to the definition above), the package is classified as next month's.
  • Packages that do not fall into either of the above categories are ignored (not added to the total weight).

Find the total weight for this month's packages and the total weight for next month's packages, respectively. If there are no applicable packages for a month, the total weight for that month is 0.

Constraints

  • 1 \leq N \leq 100
  • 2000 \leq Y \leq 2100
  • 1 \leq M \leq 12
  • 2000 \leq A_i \leq 2100 (1 \leq i \leq N)
  • 1 \leq B_i \leq 12 (1 \leq i \leq N)
  • 2000 \leq P_i \leq 2100 (1 \leq i \leq N)
  • 1 \leq Q_i \leq 12 (1 \leq i \leq N)
  • The scheduled delivery year-month P_i year Q_i month is either the same as the reception year-month A_i year B_i month, or the next month (according to the definition above). (1 \leq i \leq N)
  • 1 \leq C_i \leq 10000 (1 \leq i \leq N)
  • All input values are integers.

Input

N Y M
A_1 B_1 P_1 Q_1 C_1
A_2 B_2 P_2 Q_2 C_2
\vdots
A_N B_N P_N Q_N C_N
  • The first line contains the number of packages N, the current year Y, and the current month M, separated by spaces.
  • The following N lines, where the i-th line (1 \leq i \leq N), contains the reception year A_i, reception month B_i, scheduled delivery year P_i, scheduled delivery month Q_i, and weight C_i of the i-th package, separated by spaces.

Output

Print the total weight for this month and the total weight for next month on a single line, separated by a space. If there are no applicable packages for a month, the total weight for that month should be 0. Print a newline at the end.


Sample Input 1

3 2025 3
2025 3 2025 3 500
2025 3 2025 4 300
2025 2 2025 2 1000

Sample Output 1

500 300

Sample Input 2

4 2025 6
2025 1 2025 1 200
2025 1 2025 2 300
2025 3 2025 3 400
2025 3 2025 4 500

Sample Output 2

0 0

Sample Input 3

10 2025 12
2025 12 2025 12 100
2025 12 2026 1 200
2025 11 2025 12 300
2025 11 2025 11 150
2025 12 2026 1 400
2026 1 2026 1 500
2026 1 2026 2 250
2025 10 2025 10 600
2025 10 2025 11 700
2025 12 2025 12 350

Sample Output 3

750 1100

Sample Input 4

20 2050 7
2050 7 2050 7 100
2050 7 2050 8 200
2050 6 2050 7 300
2050 6 2050 6 400
2050 7 2050 8 500
2050 8 2050 8 150
2050 8 2050 9 250
2050 7 2050 7 350
2050 5 2050 5 1000
2050 5 2050 6 2000
2050 7 2050 8 700
2050 6 2050 7 800
2050 7 2050 7 450
2050 8 2050 8 300
2050 9 2050 9 600
2050 7 2050 8 900
2050 6 2050 6 550
2050 6 2050 7 650
2050 8 2050 8 120
2050 7 2050 7 210

Sample Output 4

2860 2870

Sample Input 5

1 2000 1
2000 1 2000 1 1

Sample Output 5

1 0