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. [UE4]计算AimOffset偏移动画的角度

  2. Android ImageView点击效果

    ImageView设置点击效果需要注意两点,第一个设置android:clickable="true",第二个 <item android:drawable="@d ...

  3. Angular2 入门详解

    AngularJS 2 快速入门 npm是什么?   npm其实是Node.js Package Manager的简称,是Node.js包管理工具(package manager) 安装Node.js ...

  4. phpstudy远程连接mysql

    格局如图所示执行以下命令 mysql -u root -p mysql>use mysql; mysql>select 'host' from user where user='root' ...

  5. pycharm中快捷键的使用

    转载自:https://blog.csdn.net/fighter_yy/article/details/40860949 Alt+Enter 自动添加包 shift+O 自动建议代码补全 Ctrl+ ...

  6. sqlserver表结构的修改

    表添加新字段 sqlserver alter table 表名 add 新增字段名 新增字段类型 是否允许为空,如: alter table [数据库名].[dbo].[表名称] add [新增字段] ...

  7. java重写LinkedList

    LinkedList重写类LinkList.java: import java.util.LinkedList;import java.util.List; public class LinkList ...

  8. redis下操作Set和Zset

    redis操作set 无序集合 元素为string类型 元素具有唯一性,不重复 命令 设置 添加元素 SADD key member [member ...]  获取 返回key集合所有的元素 SME ...

  9. spring的IOC 的底层实现原理

    IOC:Inversion of Control  控制反转. 指的是 对象的创建权反转(交给)给 Spring. 作用是实现了程序的解耦合.

  10. 《算法》第五章部分程序 part 4

    ▶ 书中第五章部分程序,包括在加上自己补充的代码,Trie 树类,Trie 集合,三值搜索树(Ternary Search Trie) ● Trie 树类 package package01; imp ...