Official

A - イベント払い戻し / Event Refund Editorial by admin Editorial for printing

DeepSeek V3

Overview

This problem requires calculating the total refund amount based on each visitor’s ticket type and purchase price. Normal tickets are refunded in full, while student discount tickets are refunded at half price (rounded down).

Analysis

The requirements are straightforward — for each visitor, we simply perform the following calculation: - If the ticket type is normal, add \(P_i\) as is - If the ticket type is half, add the integer part of \(P_i / 2\) (rounded down)

Since the input size can be as large as \(2 \times 10^5\), efficient processing is necessary. However, since the operation for each record consists only of simple arithmetic and conditional branching, it can be processed in linear time.

Algorithm

  1. Read data from standard input
  2. Get the number of people \(N\) from the first line
  3. Process each line sequentially:
    • Split by space to obtain the ticket type \(T_i\) and purchase price \(P_i\)
    • If \(T_i\) is “normal”, add \(P_i\) to the total
    • If \(T_i\) is “half”, add \(P_i // 2\) (integer division) to the total
  4. Output the final total refund amount

Complexity

  • Time complexity: \(O(N)\)
  • Space complexity: \(O(N)\) (when reading all input data at once)

Implementation Notes

  • By using integer division (//), rounding down during the half-price calculation is naturally handled

  • For reading input data, sys.stdin.read().splitlines() is used to ensure efficient processing

  • The ticket type check is a string comparison, but even with a large input size, simple conditional branching is sufficiently efficient

    Source Code

import sys

def main():
    data = sys.stdin.read().splitlines()
    n = int(data[0])
    total = 0
    for i in range(1, n + 1):
        t, p = data[i].split()
        p = int(p)
        if t == "normal":
            total += p
        else:  # t == "half"
            total += p // 2
    print(total)

if __name__ == "__main__":
    main()

This editorial was generated by deepseekv3.

posted:
last update: