#P1314. [NOIP 2011 提高组] 聪明的质监员

    ID: 312 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学2011二分NOIp 提高组前缀和

[NOIP 2011 提高组] 聪明的质监员

Description

Xiao T is a quality inspector in charge of checking a batch of ores. There are nn ores, numbered from 11 to nn. Each ore has a weight wiw_i and a value viv_i. The inspection process is:

  1. Given mm intervals [li,ri][l_i, r_i].
  2. Choose a parameter WW.
  3. For an interval [li,ri][l_i, r_i], compute the inspection value yiy_i:
$$y_i=\sum\limits_{j=l_i}^{r_i}[w_j \ge W] \times \sum\limits_{j=l_i}^{r_i}[w_j \ge W]v_j$$

Here jj is the ore index, and [p][p] is the indicator function: it returns 11 if condition pp is true, and 00 otherwise.

The overall inspection result yy for this batch is the sum of inspection values over all intervals, i.e., i=1myi\sum\limits_{i=1}^m y_i.

If the overall inspection result differs too much from the given standard value ss, another batch must be inspected. Xiao T wants to avoid extra work, so he will adjust the parameter WW to make the result as close to ss as possible, i.e., minimize sy|s - y|. Please compute this minimum value.

Input Format

The first line contains three integers n,m,sn, m, s, denoting the number of ores, the number of intervals, and the standard value.

The next nn lines each contain two integers separated by a space. The (i+1)(i+1)-th line gives the weight wiw_i and value viv_i of ore ii.

The next mm lines describe the intervals. Each line contains two integers separated by a space. The (n+i+1)(n+i+1)-th line gives the endpoints lil_i and rir_i of interval [li,ri][l_i, r_i]. Note: different intervals may coincide or overlap.

Output Format

Output a single integer, the minimum value required.

5 3 15 
1 5 
2 5 
3 5 
4 5 
5 5 
1 5 
2 4 
3 3 
10

Hint

Explanation for the sample input and output:

When WW is 44, the inspection values on the three intervals are 2020, 55, 00, so the overall result is 2525. The minimum difference from the standard value ss is 1010.

Constraints:

  • For 10%10\% of the testdata, 1n,m101 \le n, m \le 10.
  • For 30%30\% of the testdata, 1n,m5001 \le n, m \le 500.
  • For 50%50\% of the testdata, 1n,m5,0001 \le n, m \le 5{,}000.
  • For 70%70\% of the testdata, 1n,m10,0001 \le n, m \le 10{,}000.
  • For 100%100\% of the testdata, 1n,m200,0001 \le n, m \le 200{,}000, 0<wi,vi1060 < w_i, v_i \le 10^6, 0<s10120 < s \le 10^{12}, 1lirin1 \le l_i \le r_i \le n.

Translated by ChatGPT 5