SGU 477 doors

477. Doors

Time limit per test: 1.5 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



It seems that the Museum of the Modern Technology is the only place where they don't celebrate Halloween! How can they be so far from all the mistical and mysterious? You can hardly believe that two weeks ago the Museum staff have destroyed the last detail that could bring with its ominous creak a bit of Halloween atmosphere to the realm of technology. They have replaced the old wooden doors with new automatic ones, and now they are scratching their heads over how to configure the doors. 

By the order of the Director, two automatic doors were purchased. An automatic door is characterized by parameter  t , called the  , which can be set to an integer value from 1 to 10 9  during the door installation. Then the door functions on the following principle. If a person passes through the door at time  p , the door opens at time  p  -  t  and closes at time  p  +  t . There is an exceptional case when several people go in a row with a time interval not exceeding 2  t  between any two consecutive people. In this case the door opens only once,  t  seconds before the first person in the row, and it closes  t  seconds after the last person in the row has passed through it. It is very important to set the optimal values of the door parameters. On the one hand, if the doors open and close too often, it will annoy visitors. On the other hand, if both doors stay opened for a long time, visitors can get cold.

More formally, two lists of time moments are given. At the moments  p 1  <  p 2  <... <  p n  people have passed through the first door, and at the moments  q 1  <  q 2  <... <  q m  people have passed through the second one. The task is to use the given statistics to find the optimal   for the doors —  t 1  for the first door and  t 2  for the second one that satisfy the following conditions:

The total number of openings of the doors must be minimal possible. There is no continuous interval of time that both doors are opened during this interval and its length exceeds the given value  d

Input
The first line of the input contains three integers  nm and  d (1 ≤  nm ≤ 5000, 1 ≤  d ≤ 10 9). The second line contains numbers  p i, and the third line contains numbers  q i, given in the ascending order (1 ≤  p iq i ≤ 10 9).

Output
Output two integers  t 1 and  t 2, separated by a single space. If there are multiple solutions, output any. If there is no solution, output "
No solution
". 

Example(s)
sample input
sample output
3 2 4
1 6 13
7 11
3 2


题意:两个门分别设定t1,t2两个值,使得满足某些条件。

题解:首先,门的t值的一定为1或者(相邻两个间隔+1) /2。那么窝们可以枚举。但是判断两个门的公共时间是最少是o(n)的,那么如果n^2枚举坑定会跪。那么仔细一看其实o(n)枚举,给出源代码。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x) (memset((x),0x7f,sizeof((x))))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<cmp,cmq;
struct node
{
    ll a,b;
};
vectort,s;
node g;
int ansa,ansb,ans;
node mp(ll a,ll b)
{
    node re;
    re.a=a,re.b=b;
    return re;
}
void pre1(int w)
{
    s.clear();
    for(int i=0;id)return 0;
           if(j==t.size()-1||s[i].b=0&&!solve(i,sz))sz--;
        if(sz<0)break;
    }
    printf("%d %d\n",ansa,ansb);
    return 0;
}


你可能感兴趣的:(tricks)