A - A

CodeForces - 1042A

There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of nn available.

Let kk be the maximum number of people sitting on one bench after additional mm people came to the park. Calculate the minimum possible kk and the maximum possible kk.

Nobody leaves the taken seat during the whole process.

Input

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

The second line contains a single integer mm (1≤m≤10000)(1≤m≤10000) — the number of people additionally coming to the park.

Each of the next nn lines contains a single integer aiai (1≤ai≤100)(1≤ai≤100) — the initial number of people on the ii-th bench.

Output

Print the minimum possible kk and the maximum possible kk, where kk is the maximum number of people sitting on one bench after additional mm people came to the park.

Examples

Input
4
6
1
1
1
1
Output
3 7
Input
1
10
5
Output
15 15
Input
3
6
1
6
5
Output
6 12
Input
3
7
1
6
5
Output
7 13

Note

In the first example, each of four benches is occupied by a single person. The minimum kk is 33. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum kk is 77. That requires all six new people to occupy the same bench.

The second example has its minimum kk equal to 1515 and maximum kk equal to 1515, as there is just a single bench in the park and all 1010 people will occupy it.

题意:公园里有n个长椅,现在有m个人要坐在长椅上,给出每个长椅上面原来坐了多少人,求来的这m个人坐上长椅后,长椅上的人数最小的最大值,和最大的最大值

分析:最小的最大值,m个人坐上长椅后,求出每个长椅上的人数的平均值,如果平均值小于了人数最大的长椅,那么最小的最大值就是最大长椅人数;如果平均值大于了最大长椅人数,那么最小的的最大值就是该平均值,当平均值为小数的时候,还要将平均数+1.

最大的最大值,m个人坐上长椅后,最大的最大值就等于m+最大长椅人数。

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n,m,a[];
while(~scanf("%d %d",&n,&m))
{
int sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
sort(a+,a++n);//给原来长椅人数吧排序
int t,tt;
sum+=m;//所有人数之和
t=sum/n;//平均值
tt=sum%n;
if(t<a[n])//如果平均值小于最大长椅人数
{
printf("%d %d\n",a[n],a[n]+m);
}
else
{
if(tt!=)
t++;
printf("%d %d\n",t,a[n]+m);
}
}
return ;
}

B - B

CodeForces - 1042B

Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.

Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.

Input

The first line contains a single integer nn (1≤n≤1000)(1≤n≤1000) — the number of juices.

Each of the next nn lines contains an integer cici (1≤ci≤100000)(1≤ci≤100000) and a string sisi — the price of the ii-th juice and the vitamins it contains. String sisi contains from 11 to 33 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string sisi. The order of letters in strings sisi is arbitrary.

Output

Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.

Examples
input

Copy
4
5 C
6 B
16 BAC
4 A
output

Copy
15
input

Copy
2
10 AB
15 BA
output

Copy
-1
input

Copy
5
10 A
9 BC
11 CA
4 A
5 B
output

Copy
13
input

Copy
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
output

Copy
250
input

Copy
2
5 BA
11 CB
output

Copy
16
Note

In the first example Petya buys the first, the second and the fourth juice. He spends 5+6+4=155+6+4=15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 1616, which isn't optimal.

In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".

大致题意:有三种维生素,维生素A,B,C,每种橘子里至少包含一种维生素,这个人三种维生素都需要,且要求买橘子的花费最少,问你最少花费是多少

有n个橘子,下面n行,每行 c表示橘子的价钱和字符串s表示橘子所包含的维生素

代码很容易看懂,注意c++字符串格式

 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
const int mmax = 0x3f3f3f;
std::string str;
int main()
{
using namespace std;
int n;
while(~scanf("%d",&n))
{
int co,a=mmax,b=mmax,c=mmax,ab=mmax,ac=mmax,bc=mmax,abc=mmax,ans=mmax;
for(int i=;i<=n;i++)
{
cin>>co>>str;
if(str=="A")
a=min(a,co);
else if(str=="B")
b=min(b,co);
else if(str=="C")
c=min(c,co);
else if(str=="AB"||str=="BA")
ab=min(ab,co);
else if(str=="AC"||str=="CA")
ac=min(ac,co);
else if(str=="BC"||str=="CB")
bc=min(bc,co);
else
abc=min(abc,co);
}
ans=min(ans,a+bc);
ans=min(ans,b+ac);
ans=min(ans,c+ab);
ans=min(ans,ab+bc);
ans=min(ans,ab+ac);
ans=min(ans,ac+bc);
ans=min(ans,abc);
ans=min(ans,a+b+c);
if(ans==mmax)
printf("-1\n");
else
printf("%d\n",ans);
}
return ;
}

D - D

CodeForces - 1051A

Vasya came up with a password to register for EatForces — a string ss. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.

But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least one uppercase Latin letter and at least one lowercase Latin letter. For example, the passwords "abaCABA12", "Z7q" and "3R24m" are valid, and the passwords "qwerty", "qwerty12345" and "Password" are not.

A substring of string ss is a string x=slsl+1…sl+len−1(1≤l≤|s|,0≤len≤|s|−l+1)x=slsl+1…sl+len−1(1≤l≤|s|,0≤len≤|s|−l+1). lenlen is the length of the substring. Note that the empty string is also considered a substring of ss, it has the length 00.

Vasya's password, however, may come too weak for the security settings of EatForces. He likes his password, so he wants to replace some its substring with another string of the same length in order to satisfy the above conditions. This operation should be performed exactly once, and the chosen string should have the minimal possible length.

Note that the length of ss should not change after the replacement of the substring, and the string itself should contain only lowercase and uppercase Latin letters and digits.

Input

The first line contains a single integer TT (1≤T≤1001≤T≤100) — the number of testcases.

Each of the next TT lines contains the initial password s (3≤|s|≤100)s (3≤|s|≤100), consisting of lowercase and uppercase Latin letters and digits.

Only T=1T=1 is allowed for hacks.

Output

For each testcase print a renewed password, which corresponds to given conditions.

The length of the replaced substring is calculated as following: write down all the changed positions. If there are none, then the length is 00. Otherwise the length is the difference between the first and the last changed position plus one. For example, the length of the changed substring between the passwords "abcdef" →→ "a7cdEf" is 44, because the changed positions are 22 and 55, thus (5−2)+1=4(5−2)+1=4.

It is guaranteed that such a password always exists.

If there are several suitable passwords — output any of them.

Example

Input
2
abcDCE
htQw27
Output
abcD4E
htQw27

Note

In the first example Vasya's password lacks a digit, he replaces substring "C" with "4" and gets password "abcD4E". That means, he changed the substring of length 1.

In the second example Vasya's password is ok from the beginning, and nothing has to be changed. That is the same as replacing the empty substring with another empty substring (length 0).

大致题意:有T组样例,给你字符串s,把这个字符串改成符合要求的字符串,且改动长度最小,要求的字符串需要均包含大写字母,小写字母,数字。

分析:就分7种情况咯

只有小写字母 让第1,2个小写字母变为大写字母和数字

只有大写字母  让第1,2个大写字母变为小写字母和数字

只有数字 让第1,2个数字变为小写字母和大写字母

只有小写字母和大写字母   如果小写字母的数量>=2,就让其中的一个小写字母变为数字;如果大写字母的数量>=2,就让其中的一个大写字母变为数字。

只有小写字母和数字    如果小写字母的数量>=2,就让其中的一个小写字母变为大写字母;如果数字的数量>=2,就让其中的一个数字变为大写字母。

只有大写字母和数字   如果大写字母的数量>=2,就让其中的一个大写字母变为小写字母;如果数字的数量>=2,就让其中的一个数字变为小写字母。

小写字母大写字母数字都有 直接输出

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int T;
char s[];
scanf("%d",&T);
while(T--)
{
int k,ans1=,ans2=,ans3=;
scanf("%s",s);
k=strlen(s);
for(int i=;i<k;i++)
{
if(s[i]>='a'&&s[i]<='z')
ans1++;
else if(s[i]>='A'&&s[i]<='Z')
ans2++;
else if(s[i]>=''&&s[i]<='')
ans3++;
}
if(ans1>&&ans2>&&ans3>)
{
printf("%s\n",s);
}
else if(ans1>&&ans2>&&ans3==)
{
if(ans1>=)
{
for(int i=;i<k;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
s[i]='';
break;
}
}
printf("%s\n",s);
}
else if (ans2>=)
{
for(int i=;i<k;i++)
{
if(s[i]>='A'&&s[i]<='Z')
{
s[i]='';
break;
}
}
printf("%s\n",s);
} }
else if(ans1>&&ans3>&&ans2==)
{
if(ans1>=)
{
for(int i=;i<k;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
s[i]='A';
break;
}
}
printf("%s\n",s);
}
else if (ans3>=)
{
for(int i=;i<k;i++)
{
if(s[i]>=''&&s[i]<='')
{
s[i]='A';
break;
}
}
printf("%s\n",s);
}
}
else if(ans2>&&ans3>&&ans1==)
{
if(ans2>=)
{
for(int i=;i<k;i++)
{
if(s[i]>='A'&&s[i]<='Z')
{
s[i]='a';
break;
}
}
printf("%s\n",s);
}
else if (ans3>=)
{
for(int i=;i<k;i++)
{
if(s[i]>=''&&s[i]<='')
{
s[i]='a';
break;
}
}
printf("%s\n",s);
}
}
else if(ans1==&&ans2==&&ans3>)
{
printf("aA");
for(int i=;i<k;i++)
printf("%c",s[i]);
printf("\n");
}
else if(ans1==&&ans3==&&ans2>)
{
printf("a1");
for(int i=;i<k;i++)
printf("%c",s[i]);
printf("\n");
}
else if(ans2==&&ans3==&&ans1>)
{
printf("A1");
for(int i=;i<k;i++)
printf("%c",s[i]);
printf("\n");
}
}
return ;
}

You are given a set of all integers from ll to rr inclusive, l<rl<r, (r−l+1)≤3⋅105(r−l+1)≤3⋅105 and (r−l)(r−l) is always odd.

You want to split these numbers into exactly r−l+12r−l+12 pairs in such a way that for each pair (i,j)(i,j) the greatest common divisor of ii and jj is equal to 11. Each number should appear in exactly one of the pairs.

Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.

Input

The only line contains two integers ll and rr (1≤l<r≤10181≤l<r≤1018, r−l+1≤3⋅105r−l+1≤3⋅105, (r−l)(r−l) is odd).

Output

If any solution exists, print "YES" in the first line. Each of the next r−l+12r−l+12 lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (r−l+1)(r−l+1) numbers should be pairwise distinct and should have values from ll to rr inclusive.

If there are multiple solutions, print any of them.

If there exists no solution, print "NO".

Example

Input
1 8
Output
YES
2 7
4 1
3 8
6 5

题意:给你l,r,l-r一定是奇数,让你在l,r间找出(l-r+1)/2对数,一定有偶数对数,(i,j)满足最大公因数是1.

分析:每相邻的两个数的最大公因数就是1,所以遍历直接输出即可

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
long long n,m;
while(~scanf("%lld %lld",&n,&m))
{
printf("YES\n");
for(long long i=n;i<=m;i+=)
{
printf("%lld %lld\n",i,i+);
}
}
return ;
}

2018SDIBT_国庆个人第三场的更多相关文章

  1. 2018SDIBT_国庆个人第五场

    A - ACodeForces 1060A Description Let's call a string a phone number if it has length 11 and fits th ...

  2. 2018SDIBT_国庆个人第四场

    A - A  这题很巧妙啊,前两天刚好做过,而且就在博客里  Little C Loves 3 I time limit per test 1 second memory limit per test ...

  3. 2018SDIBT_国庆个人第七场

    A - Complete the Word(暴力) Description ZS the Coder loves to read the dictionary. He thinks that a wo ...

  4. 2018SDIBT_国庆个人第六场

    A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...

  5. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  6. 2018牛客网暑假ACM多校训练赛(第三场)I Expected Size of Random Convex Hull 计算几何,凸包,其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-I.html 题目传送门 - 2018牛客多校赛第三场 I ...

  7. 2018牛客网暑假ACM多校训练赛(第三场)G Coloring Tree 计数,bfs

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-G.html 题目传送门 - 2018牛客多校赛第三场 G ...

  8. 2018牛客网暑假ACM多校训练赛(第三场)D Encrypted String Matching 多项式 FFT

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-D.html 题目传送门 - 2018牛客多校赛第三场 D ...

  9. NOI.AC NOIP模拟赛 第三场 补记

    NOI.AC NOIP模拟赛 第三场 补记 列队 题目大意: 给定一个\(n\times m(n,m\le1000)\)的矩阵,每个格子上有一个数\(w_{i,j}\).保证\(w_{i,j}\)互不 ...

随机推荐

  1. 百度地图api公交路线,IE下跳转百度地图后中文变成乱码的解决办法

    百度开放的公交路线的链接,IE跳转会出现中文变成乱码的问题.如图: //创建InfoWindow function createInfoWindow() { var desDiv = []; desD ...

  2. zabbix_server.conf配置文件详解

    在TTLSA学习zabbix的同学们,来看看zabbix server配置文件参数详细讲解吧.有助于你更了解zabbix.直接往下看. AlertScriptsPath 默认值:/usr/local/ ...

  3. 点击DIV随机换颜色

    <!DOCTYPE html> <html>     <head>         <meta charset="UTF-8">   ...

  4. Docker 核心技术与实现原理

    提到虚拟化技术,我们首先想到的一定是 Docker,经过四年的快速发展 Docker 已经成为了很多公司的标配,也不再是一个只能在开发阶段使用的玩具了.作为在生产环境中广泛应用的产品,Docker 有 ...

  5. 关于微信小程序更新内容后手机上不能及时显示的办法

    这几天一直在做微信小程序的二次开发,每天都要发布程序,但是发布之后微信上查看小程序和以前的一模一样,丝毫没有改变,但是我再本地上却改变了,而且没有开的不校验合法域名那个.这是为啥呢????? 这是跟小 ...

  6. 【Git使用】SourceTree可视化工具的安装和使用攻略

    1,下载并安装 sourceTree http://downloads.atlassian.com/software/sourcetree/windows/SourceTreeSetup_1.6.14 ...

  7. h5py库安装问题解决

    H5py官网教程完全有问题,这个大家都这么说,但是貌似问题出现在Numpy上,由于numpy的版本过高! 这里是官网的教程:http://docs.h5py.org/en/latest/build.h ...

  8. Linux free -m 详解命令

    如下显示free是显示的当前内存的使用,-m的意思是M字节来显示内容.我们来一起看看. 1 2 3 4 5 6 $ free -m                total       used    ...

  9. Java file方法的路径特性

    1.在flle方法里,直接写空白的路径,是会默认获取当前Java编译工作空间的路径. 例子如下: package example_1; import java.io.File; import java ...

  10. uva-10720-贪心

    题意:对于一个简单图(不存在平行边和自旋边),输入所有的点的度,问,能不能变成一个简单图. 解题思路: 可图化定理.https://blog.csdn.net/shuangde800/article/ ...