codeforcesA. Nastya Is Reading a Book

After lessons Nastya decided to read a book. The book contains nn chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.

Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number kk as the first page which was not read (i.e. she read all pages from the 11 -st to the (k−1)(k−1) -th).

The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle).

Input

The first line contains a single integer nn (1≤n≤1001≤n≤100 ) — the number of chapters in the book.

There are nn lines then. The ii -th of these lines contains two integers lili , riri separated by space (l1=1l1=1 , li≤rili≤ri ) — numbers of the first and the last pages of the ii -th chapter. It's guaranteed that li+1=ri+1li+1=ri+1 for all 1≤i≤n−11≤i≤n−1 , and also that every chapter contains at most 100100 pages.

The (n+2)(n+2) -th line contains a single integer kk (1≤k≤rn1≤k≤rn ) — the index of the marked page.

Output

Print a single integer — the number of chapters which has not been completely read so far.

Examples

Input

Copy

3
1 3
4 7
8 11
2

Output

Copy

3

Input

Copy

3
1 4
5 9
10 12
9

Output

Copy

2

Input

Copy

1
1 7
4

Output

Copy

1

Note

In the first example the book contains 1111 pages and 33 chapters — [1;3][1;3] , [4;7][4;7] and [8;11][8;11] . Nastya marked the 22 -nd page, so she finished in the middle of the 11 -st chapter. So, all chapters has not been read so far, so the answer is 33 .

The book in the second example contains 1212 pages and 33 chapters too, but Nastya finished reading in the middle of the 22 -nd chapter, so that the answer is 22 .

题目含义:让你找总共可以阅读的时长,k为结束时间在其中的晚于他的都不行;求能阅读的章节一行为一章,一个开始一个结束

思路;求出结束时间早于或等于他的时间的章节个数即可

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
struct node{
    int x,y;
}p[100009];
bool cmp(node a,node b)
{

    return a.y<b.y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        scanf("%d%d",&p[i].x,&p[i].y);
    }
    sort(p,p+n,cmp);
    int g;
    scanf("%d",&g);int r=0;
   for(int i=0;i<n;i++)
   {

       if(p[i].y>=g)
       {
           r++;
       }
   }
    printf("%d\n",r);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-lyslyslys

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值