Codeforces Round #462 (Div. 2)(情人节掉分专场)

A. A Compatible Pair
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.

Little Tommy has n lanterns and Big Banban has m lanterns. Tommy's lanterns have brightness a1, a2, ..., an, and Banban's have brightness b1, b2, ..., bm respectively.

Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.

Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.

You are asked to find the brightness of the chosen pair if both of them choose optimally.

Input

The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 50).

The second line contains n space-separated integers a1, a2, ..., an.

The third line contains m space-separated integers b1, b2, ..., bm.

All the integers range from  - 109 to 109.

Output

Print a single integer — the brightness of the chosen pair.

Examples
input
2 2
20 18
2 14
output
252
input
5 3
-1 0 1 2 3
-1 0 1
output
2
Note

In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.

In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.

 tommy有n个灯,banban有m个,然后t灭掉自己一个ban从没灭的里面选一个然后从自己里面选一个然后t希望和尽量小b喜欢尽量大。找到那个和最大的ai个灯,关闭然后找其他的最大值就好了。

long long a[100];
long long b[100];
int main()
{
    int n,m;
	int mi=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(int i=0;i<m;i++)
        scanf("%lld",&b[i]);
    
    long long  Ma=-1e18;
    for(int i=0;i<n;i++)
	{
        for(int j=0;j<m;j++)
		{
            if(a[i]*b[j]>Ma)
			{
                Ma=a[i]*b[j];
                mi=i;
            }
        }
    }
    Ma=-1e18;
    for(int i=0;i<n;i++)
	{
        if(i==mi) 
			continue;
        for(int j=0;j<m;j++)
		{
            if(a[i]*b[j]>Ma)
			{
                 Ma=a[i]*b[j];
            }
        }
    }
    cout<<Ma<<endl;
    return 0;
}
B. A Prosperous Lot
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.

Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.

He would like to find a positive integer n not greater than 1018, such that there are exactly k loops in the decimal representation of n, or determine that such n does not exist.

loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.

Input

The first and only line contains an integer k (1 ≤ k ≤ 106) — the desired number of loops.

Output

Output an integer — if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positivedecimal integer not exceeding 1018.

Examples
input
2
output
462
input
6
output
8080
  k个0     
int main ()
{
 	long long n;
 	cin>>n;
 	if(n>36)
 		cout<<"-1\n"<<endl;
 	else
 	{
 		int t=n/2;
 		while(t--)
 		{
 			printf("8");
		}
		if(n%2==1)
			printf("4");
		printf("\n");
	}
    return 0;
}

  
C. A Twisty Movement
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.

A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence a1, a2, ..., an.

Little Tommy is among them. He would like to choose an interval [l, r] (1 ≤ l ≤ r ≤ n), then reverse al, al + 1, ..., ar so that the length of the longest non-decreasing subsequence of the new sequence is maximum.

A non-decreasing subsequence is a sequence of indices p1, p2, ..., pk, such that p1 < p2 < ... < pk and ap1 ≤ ap2 ≤ ... ≤ apk. The length of the subsequence is k.

Input

The first line contains an integer n (1 ≤ n ≤ 2000), denoting the length of the original sequence.

The second line contains n space-separated integers, describing the original sequence a1, a2, ..., an (1 ≤ ai ≤ 2, i = 1, 2, ..., n).

Output

Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence.

Examples
input
4
1 2 1 2
output
4
input
10
1 1 2 2 2 1 1 2 2 1
output
9
Note

In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4.

In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.

    

  就是翻转某个区间  求最长上升序列长。感觉类似最长上升下降序列,然后判断下就好了。

前边最多就三种情况  1-----1   1-----2  2-----2

后边往前就三种      2------1  2-----2  1-----1

举个例子    1--------1           2--------1  翻转成1--------2 翻转后边就行

                  1------2             2--------1   从第一个的2到最后翻转 变成1---------2

                  2------2            1--------1     翻转后边1-------1  变成1--------2

都可以搞成一个递增的序列

其余 算一下都一样的   最后求出来一个最大值就行

int a[2050];
int b[2050];
int c[2050];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	b[0]=1;
	for(int i=1;i<n;i++)
	{
		b[i]=1;
		for(int j=0;j<i;j++)
		{
			if(a[i]>=a[j])
			{
				b[i]=max(b[i],b[j]+1);	
			}
		}
	}
	
	c[n-1]=1;
	for(int i=n-1;i>=0;i--)
	{
		c[i]=1;
		for(int k=i+1;k<n;k++)
		{
			if(a[k]>=a[i])
			{
				c[i]=max(c[i],c[k]+1);
			}
		}
	}
	int ans=1;
	for(int i=0;i<n;i++)
	{
                ans=max(ans,b[i]+c[i+1];
	}
	printf("%d\n",ans);
	return 0;
} 

     

猜你喜欢

转载自blog.csdn.net/passer__/article/details/79327840