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. vultr 上实现高可用冗余浮动公网IP出口(使用BIRD+BGP协议)High Availability on Vultr with Floating IP and BGP

    官方文档: https://www.vultr.com/docs/high-availability-on-vultr-with-floating-ip-and-bgp https://www.vul ...

  2. 网站简介-为什么网站的ICO图标更新后,ie浏览器没有更新过来?

    为什么网站的ICO图标更新后,ie浏览器没有更新过来? 如何更新本地ico图标? 收藏夹里的网址访问后网站ico小图标怎么不会更新,还是没图标的. 如果制作了一个新的favicon.ico图标,并且已 ...

  3. SSH配置文件详解

    SSH:是一种安全通道协议,主要用来实现字符界面的远程登录,远程复制等功能. 在RHEL系统中SSH使用的是OpenSSH服务器,由opensh,openssh-server等软件包提供的. sshd ...

  4. front-end architecture

    这些东西都需要管理,并且提供一种比较好的方案去维护.在JavaScript被模块化之后,也可以通过单元测试来控制它们的质量,并且把这个过程自动化,每次版本有变更之前,保证它们最基本的正确性.最终,需要 ...

  5. 在VMware安装Centos7

    1.新建虚拟机==>典型==>稍后安装操作系统==>选择linux==>centos 64位 2.填写虚拟机名字以及安装位置. 3.磁盘容量采用默认即可. 4. 自定义硬件: ...

  6. 使用Bootstrap 基于MVC输出移动化table 列表

    基于Bootrap的列表组及栅格布局来实现 模型定义 public class StreetEvent { public int Id { get; set; } public string Stre ...

  7. hive计算周一的日期

    ) FreeMarker --',-7)?date('yyyy-MM-dd'),'week')?string('yyyy-MM-dd')}'

  8. Python网络爬虫相关基础概念

    什么是爬虫 爬虫就是通过编写程序模拟浏览器上网,然后让其去互联网上抓取数据的过程. 哪些语言可以实现爬虫    1.php:可以实现爬虫.php被号称是全世界最优美的语言(当然是其自己号称的,就是王婆 ...

  9. Linux Git install

    1.介绍 使用Coding管理项目,上面要求使用的git版本为1.8.0以上,而很多yum源上自动安装的git版本为1.7,所以需要掌握手动编译安装git方法. 2.安装git依赖包 yum inst ...

  10. Linux NTP

    1.Server 2.QuickStart last 1.Server 0.cn.pool.ntp.org 1.cn.pool.ntp.org 2.cn.pool.ntp.org 3.cn.pool. ...