CSU 1335: Takahashi and Low Bridge (two points + sweep balloons)

Source: Internet
Author: User

1335: Takahashi and Low bridge time limit:1 Sec Memory limit:128 MB
submit:861 solved:248
[Submit] [Status] [Web Board] Description

One of the brain teasers is this: there is a very close to a low two bridge, two floods after the Takahashi was flooded two times, the low bridge was only flooded once, why? The answer is: Because the low bridge is too low, the first flood after the water is still on the low bridge, so does not count as "flooded two times." To illustrate:

It is assumed that the height of Takahashi and Low Bridge is 5 and 2, the initial water level is 1

First flood: water level raised to 6 (two bridges flooded), retreated to 2 (Takahashi no longer flooded, but low bridge is still flooded)

Second flood: The water level was raised to 8 (Takahashi was flooded again) and retreated to 3.

Yes, word games. The key is the meaning of "another". If a bridge is still flooded after a flood has receded (that is, the water level is not less than the height of the bridge), then the next flood will not be "flooded" once again.

Enter the height of the N bridge and the swollen level AI and water level bi for the flood of the first I, and count how many bridges have been flooded at least k times. The initial water level is 1, and the swollen water level of each flood must be greater than the water level of the last flood.

Input

The input file contains up to 25 sets of test data. The first behavior of each group of data is three integers n, m, K (1<=n,m,k<=105). The second behavior is n integers hi (2<=hi<=108), which is the height of each bridge. The following m lines contain two integers of AI and bi (1<=bi<ai<=108, ai>bi-1) per line. The input file does not exceed 5MB.

Output

For each set of data, output the number of bridges that have been flooded at least k times.

Sample Input
2 2 22 56 28 35 3 22 3 4 5 65 34 25 2
Sample Output

Case 1:1case 2:3


#include <cstring> #include <cstdio> #include <algorithm> #include <iostream> #include < cmath> #include <queue> #include <map> #include <vector> #include <string> #define LL Long Long    #define N 100010using namespace Std;int n,m,k;int h[n];int num[n];int main () {int ca=1;        while (~SCANF ("%d%d%d", &n,&m,&k)) {memset (num,0,sizeof num);        for (int i=0; i<n; i++) {scanf ("%d", &h[i]);        } sort (h,h+n);        int oldh=1;            while (m--) {int x, y;            scanf ("%d%d", &x,&y);            int L=lower_bound (H,H+N,OLDH)-H;            int R=upper_bound (H,H+N,X)-H;            while (H[L]==OLDH) l++;            while (h[r]>x) r--;            Num[l]+=1;            Num[r+1]-=1;        Oldh=y;        } int ans=num[0]>=k?1:0;            for (int i=1; i<n; i++) {num[i]+=num[i-1];        if (num[i]>=k) ans++;    } printf ("Case%d:%d\n", Ca++,ans);}} 


CSU 1335: Takahashi and Low Bridge (two points + sweep balloons)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.