Mouse Pursuit

면접 대비

시간 제한3초메모리 제한2048 MB

요약
몇 초 전에 일어났는지로 시간이 주어진 사건들에서 최근 k초 안에 속하는 사건의 치즈와 영광 획득량을 부호까지 반영해 각각 합산한다.
난이도

쉬움10점 중 3점

유형
배열, 정렬, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Brandon is playing the newest idle game, Mouse Pursuit! The goal of this game is to pursue mice for cheese and glory.

In Mouse Pursuit, an event consists of pursuing a mouse. If the mouse is caught, the player might earn cheese and glory. However, if the mouse is not caught, the player might lose cheese and glory.

Given Brandon's recent events, Brandon wants to know how much cheese and glory he earned in the last kk seconds.

입력

The first line of input contains a single integer, nn (1≤n≤105)(1 \le n \le 10^5).

The next nn lines take one of two forms:

  • CAUGHT\text{CAUGHT} ss cc gg: A mouse was caught exactly ss seconds ago. The player gained cc pieces of cheese and gg units of glory.
  • MISS\text{MISS} ss cc gg: A mouse was missed exactly ss seconds ago. The player lost cc pieces of cheese and gg units of glory.

For all events, 0≤c,g≤1060 \le c, g \le 10^6 and 1≤s≤1091 \le s \le 10^9. It is guaranteed that no two events happened at exactly the same time.

The last line contains a single integer kk. It is guaranteed that no event happened exactly kk seconds ago.

출력

Output two integers - the number of pieces of cheese Brandon gained in the last kk seconds, and the number of units of glory Brandon gained in the last kk seconds.

예제1

  1. 예제 1

    입력
    3
    CAUGHT 1 6 5
    MISS 4 1 2
    CAUGHT 8 0 3
    5
    
    예상 출력
    5 3