#P1311. [NOIP 2011 提高组] 选择客栈

[NOIP 2011 提高组] 选择客栈

Description

Along the Lijiang River, there are nn distinctive inns, numbered from 11 to nn in order of their locations. Each inn is decorated in one of kk hues (represented by integers 0k10 \sim k-1), and each inn has a coffee shop with its own minimum charge.

Two tourists are traveling together. They like the same hue but want to try two different inns, so they decide to stay at two inns with the same hue. At night, they plan to choose a coffee shop to have coffee. The coffee shop must be located between the two inns they stay at (including the inns themselves), and its minimum charge must not exceed pp.

They want to know the total number of ways to choose their accommodations such that they can find a coffee shop whose minimum charge is no more than pp yuan at night.

Input Format

There are n+1n+1 lines.

The first line contains three integers n,k,pn, k, p, separated by single spaces, representing the number of inns, the number of hues, and the maximum acceptable minimum charge, respectively.

For the next nn lines, the (i+1)(i+1)-th line contains two integers, separated by a single space, denoting the hue aia_i of inn ii and the minimum charge bib_i of the coffee shop of inn ii.

Output Format

Output a single integer, the total number of valid accommodation choices.

5 2 3 
0 5 
1 3 
0 2 
1 4 
1 5 

3

Hint

Sample Explanation.

Since the two people must stay in inns with the same hue, all possible choices include: inns 11 and 33, 22 and 44, 22 and 55, 44 and 55. However, if they choose inns 4,54,5, the minimum charge of the coffee shops between inns 44 and 55 is 44, while their acceptable minimum charge is 33 yuan, so this does not satisfy the requirement. Therefore, only the first 33 choices are valid.

Constraints.

  • For 30%30\% of the testdata, n100n \leq 100.
  • For 50%50\% of the testdata, n1000n \leq 1\,000.
  • For 100%100\% of the testdata, 2n2×1052 \leq n \leq 2 \times 10^5, 1k501 \leq k \leq 50, 0p1000 \leq p \leq 100, 0bi1000 \leq b_i \leq 100.

Translated by ChatGPT 5