Educational Codeforces Round 39 (Rated for Div. 2)

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

You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.

Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.

The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.

Output

Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.

Examples
Input
Copy
3
1 -2 0
Output
Copy
3
Input
Copy
6
16 23 16 15 42 8
Output
Copy
120
Note

In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C =  - 2, B - C = 3.

In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.

题意:输入n个数,输出最大和和最小和只差。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 110;
int vis[maxn];

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i = 1; i <= n; i ++)
			scanf("%d",&vis[i]);
		sort(vis+1,vis+1+n);
		int sum1 = 0;
		int sum2 = 0;
		for(int i = 1; i <= n;i ++)
		{
			if(vis[i] <= 0)
				sum1 += vis[i];
			else
				sum2 += vis[i];
		}
		printf("%d\n",sum2-sum1);
	}
	return 0;
}

B. Weird Subtraction Process
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have two variables a and b. Consider the following sequence of actions performed with these variables:

  1. If a = 0 or b = 0, end the process. Otherwise, go to step 2;
  2. If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
  3. If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.

Initially the values of a and b are positive integers, and so the process will be finite.

You have to determine the values of a and b after the process ends.

Input

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b.

Output

Print two integers — the values of a and b after the end of the process.

Examples
Input
Copy
12 5
Output
Copy
0 1
Input
Copy
31 12
Output
Copy
7 12
Note

Explanations to the samples:

  1. a = 12, b = 5 a = 2, b = 5 a = 2, b = 1 a = 0, b = 1;
  2. a = 31, b = 12 a = 7, b = 12.

题意:按照题目所述,输出a和b的值。

思路:一开始是模拟,因为没有看数据范围,后来企图用大数的方式过,其实longl long 就行了啊,当时估计脑子抽了~~最后还是不行,百度题解才知道是辗转相除。。。。嗯嗯 ,仔细想想确实也是啊,反正就两种情况,a>=2*b,b>=2*a,相减改为取余。

#include<stdio.h>

int main()
{
	long long a,b;
	while(scanf("%lld%lld",&a,&b)!=EOF)
	{
		int flag = 1;
		while(a&&b)
		{
			if(a>=2*b)
				a = a%(2*b);
			else if( b >= 2*a)
				b = b%(2*a);
			else
				break;
		}
		printf("%lld %lld\n",a,b);
	}
	return 0;
}

C. String Transformation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string s consisting of |s| small english letters.

In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.

Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.

Input

The only one line of the input consisting of the string s consisting of |s| (1 ≤ |s| ≤ 105) small english letters.

Output

If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).

Examples
Input
Copy
aacceeggiikkmmooqqssuuwwyy
Output
Copy
abcdefghijklmnopqrstuvwxyz
Input
Copy
thereisnoanswer
Output
Copy
-1

题意:给定的字符串,有字母a~z组成,任意一个字母可以变成它在字母表中的下一个字母,比如a可以变成b,z不能变,问,输入的字符串在经过改变后能否存在a~z字母组成的子序列。

思路:题意有点难理解,交上去WA一次,其实就是从a开始,往后遍历,只要遇到小于等于a的字母,就赋值为a,并且a的值也要增加,这样才能保证形成a~z的序列。

结:虽然这道题,看了题解以后发觉并不难,而且思路和当时我脑海中的一种想法很符合,但是我没有继续想下去,总是怕错。。。。这样可不行,写不出来题的情况下,想法再离谱也得去尝试,否则,比赛的时候,谁来帮自己呢~~~


#include<stdio.h>
#include<string.h>
const int maxn = 100010;
char vis[maxn];
char str[26] ;
int main()
{
	while(scanf("%s",vis)!=EOF)
	{
		char ch = 'a';
		for(int i = 0;vis[i]!='\0';i++)
		{
			if(ch == 'z'+1)
				break;
			if(vis[i] <= ch)
				vis[i] = ch ++;
		}
		
		if(ch == 'z'+1)
			printf("%s\n",vis);
		else
			printf("-1\n");
	}
	return 0;
}



阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页