QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#18668. 狐獴

Statistics

由 $N$ 隻狐獴組成的狐獴家族過著群體生活。白天,狐獴們為了應對天敵,從洞穴中出來,在 $1$ 維座標上站崗。每隻狐獴站崗時,其位置和注視方向(左或右)是固定的,並且在站崗期間無法改變注視方向。

狐獴家族中所有狐獴的身高都不同,如果比自己高的狐獴站在自己所注視的方向,則該狐獴會無法看到外面。你對此感到憐憫,可以在狐獴家族不知情的情況下自由執行以下操作:

  • 面向相同方向的狐獴中選擇兩隻,交換它們的位置。

請計算在適當執行上述操作後,最多有多少隻狐獴能夠看到外面。

輸入格式

第一行給定狐獴的數量 $N$。($3 \leq N \leq 5\,000$)

接下來 $N$ 行,每行給定一隻狐獴的資訊。對於所有 $1 \leq i \leq N$,第 $(i+1)$ 行給定從左邊數來第 $i$ 隻狐獴的身高整數 $A_i$ 和注視方向字元 $D_i$,以空格分隔。($1\leq A_i \leq N$)$D_i$ 為 L 表示向左,R 表示向右。

所有 $A_i$ 互不相同。

輸出格式

第一行輸出最多有多少隻狐獴能夠看到外面。

範例

輸入範例 1

5
5 L
2 R
3 R
4 R
1 L

輸出範例 1

4

輸入範例 2

7
7 R
1 L
6 R
3 L
5 L
4 R
2 R

輸出範例 2

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.