训练赛20190310

B - Glider

 

A plane is flying at a constant height of hh meters above the ground surface. Let's consider that it is flying from the point (−109,h)(−109,h) to the point (109,h)(109,h) parallel with OxOx axis.

A glider is inside the plane, ready to start his flight at any moment (for the sake of simplicity let's consider that he may start only when the plane's coordinates are integers). After jumping from the plane, he will fly in the same direction as the plane, parallel to OxOx axis, covering a unit of distance every second. Naturally, he will also descend; thus his second coordinate will decrease by one unit every second.

There are ascending air flows on certain segments, each such segment is characterized by two numbers x1x1 and x2x2 (x1<x2x1<x2) representing its endpoints. No two segments share any common points. When the glider is inside one of such segments, he doesn't descend, so his second coordinate stays the same each second. The glider still flies along OxOx axis, covering one unit of distance every second.

 If the glider jumps out at 11, he will stop at 1010. Otherwise, if he jumps out at 22, he will stop at 1212.

Determine the maximum distance along OxOx axis from the point where the glider's flight starts to the point where his flight ends if the glider can choose any integer coordinate to jump from the plane and start his flight. After touching the ground the glider stops altogether, so he cannot glide through an ascending airflow segment if his second coordinate is 00.

Input

The first line contains two integers nn and hh (1≤n≤2⋅105,1≤h≤109)(1≤n≤2⋅105,1≤h≤109) — the number of ascending air flow segments and the altitude at which the plane is flying, respectively.

Each of the next nn lines contains two integers xi1xi1 and xi2xi2 (1≤xi1<xi2≤109)(1≤xi1<xi2≤109) — the endpoints of the ii-th ascending air flow segment. No two segments intersect, and they are given in ascending order.

Output

Print one integer — the maximum distance along OxOx axis that the glider can fly from the point where he jumps off the plane to the point where he lands if he can start his flight at any integer coordinate.

Examples

Input

3 4
2 5
7 9
10 11

Output

10

Input

5 10
5 7
11 12
16 20
25 26
30 33

Output

18

Input

1 1000000000
1 1000000000

Output

1999999999

Note

In the first example if the glider can jump out at (2,4)(2,4), then the landing point is (12,0)(12,0), so the distance is 12−2=1012−2=10.

In the second example the glider can fly from (16,10)(16,10) to (34,0)(34,0), and the distance is 34−16=1834−16=18.

In the third example the glider can fly from (−100,1000000000)(−100,1000000000) to (1999999899,0)(1999999899,0), so the distance is 1999999899−(−100)=199999999

题意:

从飞机上跳伞,正常情况下每秒向右移动一格,向下落一格,当遇到气流时,不会降落,问最远可以飞多远

我们可以想到两个气流区域中间的部分其实就是会降落的高度,所以问题就转化为了在不超过h的空区域之和的情况下,通过的气流的长度+高度h。

所以我们可以用前缀和来维护空区域的长度和气流的长度,在通过lower_bound函数查找从每一个起点(即各个气流区域的起点)开始的空区域之和小于H的中最长的即可。

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
struct node
{
    int x,y;
}a[N];
int n,h;
int wid[N],kong[N];
int main()
{
    while(~scanf("%d%d",&n,&h)){
            memset(wid,0,sizeof(wid));
            memset(kong,0,sizeof(kong));
        scanf("%d%d",&a[1].x,&a[1].y);
        kong[1]=0;
        wid[1]=a[1].y-a[1].x;
        for(int i=2;i<=n;i++){
            scanf("%d%d",&a[i].x,&a[i].y);
            kong[i]=a[i].x-a[i-1].y;
            kong[i]+=kong[i-1];
            wid[i]=a[i].y-a[i].x;
            wid[i]+=wid[i-1];
        }
          /*for(int i=1;i<=n;i++)
            cout<<wid[i]<<endl;*/
        int ans=-1;
        for(int i=1;i<=n;i++){
            int p=lower_bound(kong+1,kong+1+n,kong[i]+h)-kong;
           // cout<<p<<" "<<kong[p]<<endl;
             ans=max(ans,wid[p-1]-wid[i-1]+h);
        }
        printf("%d\n",ans);
    }
}

C - Bacteria

 

Recently Monocarp has created his own mini-laboratory!

The laboratory contains nn bacteria. Monocarp knows that he can merge any two bacteria having equal sizes, and the resulting bacterium will have the size equal to the sum of sizes of merged bacteria. For example, if two bacteria having sizes equal to 77 merge, one bacterium with size 1414 is the result.

It becomes hard to watch for many bacteria, so Monocarp wants to merge all of them into one bacterium. It may not be possible to do this with the bacteria Monocarp has, so he can buy any number of bacteria of any possible integer sizes in a special store.

You have to determine the minimum number of bacteria Monocarp has to buy to merge them with the nn bacteria his laboratory contains into exactly one bacterium.

Input

The first line contains one integer nn (1≤n≤2⋅105)(1≤n≤2⋅105) — the number of bacteria Monocarp's laboratory contains.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109), where aiai is the size of the ii-th bacterium in the laboratory.

Output

If it is impossible to merge the bacteria (possibly after buying some) into only one bacterium, print -1.

Otherwise print the minimum number of bacteria Monocarp has to buy to merge them with the nn bacteria his laboratory contains into exactly one bacterium.

Examples

Input

2
1 4

Output

2

Input

3
3 6 9

Output

-1

Input

7
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Output

1

Note

In the first example Monocarp should buy one bacterium having size 11 and one bacterium having size 22. Then Monocarp will have 44 bacteria having sizes [1,4,1,2][1,4,1,2]. Then two bacteria having sizes 11 can be merged into one having size 22. Then Monocarp will have 33 bacteria having sizes [2,4,2][2,4,2]. Then two bacteria having sizes 22 can be merged into one having size 44. Then Monocarp will have 22 bacteria having sizes [4,4][4,4], which can be merged into one having size 88.

In the second example no matter which bacteria Monocarp will buy, he cannot merge all his bacteria.

In the third example Monocarp needs to buy one bacterium having size 10000000001000000000.

题意:两个同样大小的细菌可以合并,如果没有一样大的,需要买一个。。。直到合并为一个,问至少需要买几个,若始终不能合并成一个,输出-1

很明显,不能合并成一个的条件就是最后剩下的两个不相等并且当小的那个数乘2大于另一个数,这样是无论如何都不能合并成一个的;

这里用优先队列维护即可。

#include<bits/stdc++.h>
using namespace std;
int n;
priority_queue<long long,vector<long long>,greater<long long> >q;
long long gcd(long long m,long long n)
{
   while(m>0)
   {
     long long c=n%m;
         n=m;
         m=c;
    }
return n;
}
int main()
{
    while(~scanf("%d",&n)){
        int x;
        while(!q.empty())
            q.pop();
        for(int i=1;i<=n;i++){
            scanf("%d",&x);
            q.push(x);
        }
        int ans=0;
        bool flag=true;
        while(!q.empty()){
            long long p1=q.top();
            q.pop();
            long long p2=q.top();
            q.pop();
            if(q.empty()){
                if(p1!=p2&&p1*2>p2){
                        flag=false;
                      break;
                }
            }
            if(p1==p2){
                p1+=p2;
                q.push(p1);
            }
            else{
                p1=p1*2;
                ans++;
                q.push(p2);
                q.push(p1);
            }
        }
        if(flag)
            printf("%d\n",ans);
        else printf("-1\n");
    }
}

H - Theater Square

The Theater Square can be represented as a rectangle having height nn and length mm, divided into square 1×11×1 cells. Let's denote the cell located at the intersection of ii-th row and jj-th column as (i,j)(i,j). The rows are numbered from top to bottom, the columns — from left to right.

There is a rectangular fountain inside the Teather Square. The cell in its left upper corner is (x1,y1)(x1,y1), the cell in its right lower corner is (x2,y2)(x2,y2).

The Theater Square soon will be paved with tiles having height 11 and length 22. Every cell (except cells inside the fountain) should be paved, and no cell should be covered by more than one tile. All tiles will be laid out horizontally, so the cells covered by each tile are in the same row. To pave the whole Theater Square it might be necessary to break some tiles. After breaking a tile, two new tiles of size 1×11×1are formed (which cannot be broken further). You may consider that the mayor, who ordered the paving of the Theater Square, has infinite number of tiles 1×21×2.

Since broken tiles are not beautiful, among all possible ways to pave the Theater Square the mayor wants to choose a way such that the number of tiles to be broken into two lesser tiles is minimum possible. Pay attention that tiles should be laid horizontally, no tile can cover cells in different rows.

Help the mayor! Tell him the minimum possible number of tiles to be broken.

Input

The first line contains two integers nn and mm (1≤n,m≤2⋅105)(1≤n,m≤2⋅105) — the height and the length of the Theater Square, respectively.

The second line contains four numbers x1,y1,x2,y2 (1≤x1≤x2≤n,1≤y1≤y2≤m)x1,y1,x2,y2 (1≤x1≤x2≤n,1≤y1≤y2≤m) — the coordinates of left upper corner and right lower corner of the fountain.

Output

Print one number — minimum possible number of tiles mayor has to break in order to pave the whole Theater Square.

Examples

Input

6 5
1 2 3 4

Output

5

Input

6 1
3 1 4 1

Output

2

Input

1 12
1 3 1 8

Output

0

Note

One of the optimal ways to pave the Theater Square in the first example:

55 tiles are to be broken.

题意:有一个n×m的广场,需要铺设1×2的砖,广场里还有一个喷泉,1×2的砖可以分成1×1的砖,问至少需要几块1×2的砖分成1×1的砖?

,这个题可以先求需要的1×1的砖的数量,最后除2向上取整即可,1×1的砖按照喷泉的左右剩下的列数判断即可,奇数就需要一列,另外喷泉没有占到的行也判断一下,列数如果是奇数,也需要一列。

#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int main()
{
    int x1,x2,y1,y2;
    while(~scanf("%d%d",&n,&m)){
            ans=0;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        if((y1-1)&1){
            ans+=x2-x1+1;
        }
        if((m-y2)&1){
            ans+=x2-x1+1;
        }
        if(m&1){
            ans+=x1-1+n-x2;
        }
        printf("%d\n",ans%2==0?ans/2:(ans/2)+1);
    }
}

I - Heist

There was an electronic store heist last night.

All keyboards which were in the store yesterday were numbered in ascending order from some integer number xx. For example, if x=4x=4 and there were 33 keyboards in the store, then the devices had indices 44, 55 and 66, and if x=10x=10 and there were 77 of them then the keyboards had indices 1010, 1111, 1212, 1313, 1414, 1515 and 1616.

After the heist, only nn keyboards remain, and they have indices a1,a2,…,ana1,a2,…,an. Calculate the minimum possible number of keyboards that have been stolen. The staff remember neither xx nor the number of keyboards in the store before the heist.

Input

The first line contains single integer nn (1≤n≤1000)(1≤n≤1000) — the number of keyboards in the store that remained after the heist.

The second line contains nn distinct integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109) — the indices of the remaining keyboards. The integers aiai are given in arbitrary order and are pairwise distinct.

Output

Print the minimum possible number of keyboards that have been stolen if the staff remember neither xx nor the number of keyboards in the store before the heist.

Examples

Input

4
10 13 12 8

Output

2

Input

5
7 5 6 4 8

Output

0

Note

In the first example, if x=8x=8 then minimum number of stolen keyboards is equal to 22. The keyboards with indices 99 and 1111 were stolen during the heist.

In the second example, if x=4x=4 then nothing was stolen during the heist.

题意:商店里有下标递增的键盘,突然商店被盗,有一些键盘丢失,问最少丢了多少个键盘

水题,找出剩下的键盘中下标最大的和最小的,max-min+1即可求出个数,在减去n即可。

#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<cstdlib>
using namespace std;
#define ios   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);'
#define ll long long
const int maxn=1000005;
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int n;
int main()
{
    while(~scanf("%d",&n)){
        int minx,maxn;
        minx=0x3f3f3f3f;
        maxn=-1;
        int m;
        for(int i=1;i<=n;i++){
            scanf("%d",&m);
            if(m>maxn)
                maxn=m;
            if(m<minx)
                minx=m;
        }
        printf("%d\n",maxn-minx+1-n);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在工程训练赛中,多垃圾分类是一个常见的任务。参赛者通常会使用不同的硬件设备和训练方法来完成这个任务。例如,有人使用Jetson Nano 4B作为垃圾桶的控制器,使用自己的Win10电脑进行垃圾分类的训练\[2\]。在训练过程中,数据集的大小和训练时间是需要考虑的因素。虽然本地训练的数据集没有网站上的20MB限制,但是数据集越大,训练时间就越长。一般来说,迭代次数在60左右,当loss降到0.1左右,accuracy为0.9左右时,模型的效果还算可以\[1\]。此外,为了提高模型的准确性,建议保证光亮的环境下拍摄数据集,并确保各物体数据集之间有明显的差异和丰富的背景\[1\]。 #### 引用[.reference_title] - *1* *3* [第七届工程训练比赛之智能垃圾分类](https://blog.csdn.net/qq_54693299/article/details/115942615)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [第七届全国大学生工程训练大赛智能+赛道生活垃圾分类垃圾训练步骤(win10+yolov4-tiny)](https://blog.csdn.net/qq_43577213/article/details/118420376)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值