2018SDIBT_国庆个人第三场

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

461111

Output

3 7

Input

1105

Output

15 15

Input

36165

Output

6 12

Input

37165

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+最大长椅人数。

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,m,a[105];
 8     while(~scanf("%d %d",&n,&m))
 9     {
10          int sum=0;
11          for(int i=1;i<=n;i++)
12          {
13              scanf("%d",&a[i]);
14              sum+=a[i];
15          }
16          sort(a+1,a+1+n);//给原来长椅人数吧排序
17          int  t,tt;
18          sum+=m;//所有人数之和
19          t=sum/n;//平均值
20          tt=sum%n;
21          if(t<a[n])//如果平均值小于最大长椅人数
22          {
23              printf("%d %d\n",a[n],a[n]+m);
24          }
25          else
26          {
27              if(tt!=0)
28                 t++;
29              printf("%d %d\n",t,a[n]+m);
30          }
31     }
32     return 0;
33 }

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

45 C6 B16 BAC4 A

output

Copy

15

input

Copy

210 AB15 BA

output

Copy

-1

input

Copy

510 A9 BC11 CA4 A5 B

output

Copy

13

input

Copy

6100 A355 BCA150 BC160 AC180 B190 CA

output

Copy

250

input

Copy

25 BA11 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++字符串格式

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 const int mmax = 0x3f3f3f;
 6 std::string str;
 7 int main()
 8 {
 9     using namespace std;
10     int n;
11     while(~scanf("%d",&n))
12     {
13         int co,a=mmax,b=mmax,c=mmax,ab=mmax,ac=mmax,bc=mmax,abc=mmax,ans=mmax;
14         for(int i=1;i<=n;i++)
15         {
16             cin>>co>>str;
17             if(str=="A")
18                 a=min(a,co);
19             else if(str=="B")
20                 b=min(b,co);
21             else if(str=="C")
22                 c=min(c,co);
23             else if(str=="AB"||str=="BA")
24                 ab=min(ab,co);
25             else if(str=="AC"||str=="CA")
26                 ac=min(ac,co);
27             else if(str=="BC"||str=="CB")
28                 bc=min(bc,co);
29             else
30                 abc=min(abc,co);
31         }
32         ans=min(ans,a+bc);
33         ans=min(ans,b+ac);
34         ans=min(ans,c+ab);
35         ans=min(ans,ab+bc);
36         ans=min(ans,ab+ac);
37         ans=min(ans,ac+bc);
38         ans=min(ans,abc);
39         ans=min(ans,a+b+c);
40         if(ans==mmax)
41             printf("-1\n");
42         else
43         printf("%d\n",ans);
44     }
45     return 0;
46 }

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

2abcDCEhtQw27

Output

abcD4EhtQw27

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,就让其中的一个数字变为小写字母。

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

  1 #include<cstdio>
  2 #include<algorithm>
  3 #include<cstring>
  4 using namespace std;
  5 int main()
  6 {
  7     int T;
  8     char s[105];
  9     scanf("%d",&T);
 10     while(T--)
 11     {
 12         int k,ans1=0,ans2=0,ans3=0;
 13         scanf("%s",s);
 14         k=strlen(s);
 15         for(int i=0;i<k;i++)
 16         {
 17             if(s[i]>=‘a‘&&s[i]<=‘z‘)
 18                 ans1++;
 19             else if(s[i]>=‘A‘&&s[i]<=‘Z‘)
 20                 ans2++;
 21             else if(s[i]>=‘0‘&&s[i]<=‘9‘)
 22                 ans3++;
 23         }
 24         if(ans1>0&&ans2>0&&ans3>0)
 25         {
 26             printf("%s\n",s);
 27         }
 28         else if(ans1>0&&ans2>0&&ans3==0)
 29         {
 30             if(ans1>=2)
 31             {
 32                 for(int i=0;i<k;i++)
 33                 {
 34                     if(s[i]>=‘a‘&&s[i]<=‘z‘)
 35                     {
 36                         s[i]=‘1‘;
 37                         break;
 38                     }
 39                 }
 40                 printf("%s\n",s);
 41             }
 42             else if (ans2>=2)
 43             {
 44                 for(int i=0;i<k;i++)
 45                 {
 46                     if(s[i]>=‘A‘&&s[i]<=‘Z‘)
 47                     {
 48                         s[i]=‘1‘;
 49                         break;
 50                     }
 51                 }
 52                 printf("%s\n",s);
 53             }
 54
 55         }
 56         else if(ans1>0&&ans3>0&&ans2==0)
 57         {
 58             if(ans1>=2)
 59             {
 60                 for(int i=0;i<k;i++)
 61                 {
 62                     if(s[i]>=‘a‘&&s[i]<=‘z‘)
 63                     {
 64                         s[i]=‘A‘;
 65                         break;
 66                     }
 67                 }
 68                 printf("%s\n",s);
 69             }
 70             else if (ans3>=2)
 71             {
 72                 for(int i=0;i<k;i++)
 73                 {
 74                     if(s[i]>=‘0‘&&s[i]<=‘9‘)
 75                     {
 76                         s[i]=‘A‘;
 77                         break;
 78                     }
 79                 }
 80                 printf("%s\n",s);
 81             }
 82         }
 83         else if(ans2>0&&ans3>0&&ans1==0)
 84         {
 85             if(ans2>=2)
 86             {
 87                 for(int i=0;i<k;i++)
 88                 {
 89                     if(s[i]>=‘A‘&&s[i]<=‘Z‘)
 90                     {
 91                         s[i]=‘a‘;
 92                         break;
 93                     }
 94                 }
 95                 printf("%s\n",s);
 96             }
 97             else if (ans3>=2)
 98             {
 99                 for(int i=0;i<k;i++)
100                 {
101                     if(s[i]>=‘0‘&&s[i]<=‘9‘)
102                     {
103                         s[i]=‘a‘;
104                         break;
105                     }
106                 }
107                 printf("%s\n",s);
108             }
109         }
110         else if(ans1==0&&ans2==0&&ans3>0)
111         {
112             printf("aA");
113             for(int i=2;i<k;i++)
114                 printf("%c",s[i]);
115             printf("\n");
116         }
117         else if(ans1==0&&ans3==0&&ans2>0)
118         {
119             printf("a1");
120             for(int i=2;i<k;i++)
121                 printf("%c",s[i]);
122             printf("\n");
123         }
124         else if(ans2==0&&ans3==0&&ans1>0)
125         {
126             printf("A1");
127             for(int i=2;i<k;i++)
128                 printf("%c",s[i]);
129             printf("\n");
130         }
131     }
132     return 0;
133 }

E - E

CodeForces - 1051B

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

YES2 74 13 86 5

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

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

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 using namespace std;
 5 int main()
 6 {
 7     long long n,m;
 8     while(~scanf("%lld %lld",&n,&m))
 9     {
10         printf("YES\n");
11         for(long long i=n;i<=m;i+=2)
12         {
13             printf("%lld %lld\n",i,i+1);
14         }
15     }
16     return 0;
17 }

原文地址:https://www.cnblogs.com/LLLAIH/p/9740311.html

时间: 2024-10-02 12:15:06

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

2018SDIBT_国庆个人第四场

A - A  这题很巧妙啊,前两天刚好做过,而且就在博客里 Little C Loves 3 I time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little C loves number «3» very much. He loves all things about it. Now he has a positive int

2018SDIBT_国庆个人第五场

A - ACodeForces 1060A Description Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are ph

2018SDIBT_国庆个人第七场

A - Complete the Word(暴力) Description ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once.

最近打的三场比赛的总结

10.25 上午 省常中模拟赛 比赛题目刚发下来,看到出题人之后我就变得紧张起来,因为暑假的时候也做过一份他出的题,题目难到连全场最高分也不过 100 多分,所以又一次做到他出的题难免有些心理阴影. 这种心态直接导致了我在第一题上的失误.由于在心里认为这场模拟赛的难度应该较高,导致我对于第一题几乎不假思索就认为是动规,而根本没有往更简单的方向去想.我一开始想到的是区间动规,但是发现只能拿 50 分,想了一会儿还是没什么思路,于是先把区间动规打好然后打第二题. 第二题是一道比较不错的题,但是由于强

计蒜之道2015程序设计大赛初赛第三场——腾讯手机地图

计蒜之道2015程序设计大赛初赛第三场——腾讯手机地图 (一)题面 腾讯手机地图的定位功能用到了用户手机的多种信号,这其中有的信号的作用范围近,有的信号作用的范围则远一些.有的信号相对于用户在不同的方位强度是不同的,有的则是在任何一个方向上信号强度都一致的. 已知用户面向北方拿着自己的手机,在不同方位的各种信号覆盖区域可以被抽象成以用户为圆心的一系列扇形.已知每个扇形的半径 r,和每个扇形的两条边相对于正东方向的夹角度数.每个信号覆盖区域抽象出的扇形都可以通过从第一条边逆时针旋转到第二条边画出.

2014多校第三场1005 || HDU 4891 The Great Pan(模拟)

题目链接 题意 : 给你n行字符串,问你有多少种理解方式.有两大类的理解 (1){A|B|C|D|...}代表着理解方式可以是A,可以是B或C或者D. (2)$blah blah$,在$$这两个符号中间,如果是不连续的空格的那个位置就有2种理解方式,可以理解为没有空格也可以理解为有空格.如果有连续N个空格的位置,那里就有N+1种理解方式. 最后所有的理解方式相乘,数据保证$一定与$匹配,{一定与匹配},不会有任何嵌套,类似{$$}或者{{}}或者${}$这种情况都不会出现,也不会有{$}这种情况

hdu-4893-Wow! Such Sequence!-线段树【2014多校第三场-J】

题意:一个初始为0的数组,支持三种操作:1.向第k个数添加d,(|d| < 2^31);2.把[l, r]区间内的数字都换成与它最相近的Fibonacci数;3.询问[l, r]区间的和. 思路:初始化Fibonacci数组,longlong 类型内90个就够用了. 线段树区间查询,用lazy标记, sgt[]记录线段树各个节点的区间和, fib_num_sum[]记录与各个叶子节点当前值最接近的Fibonacci数,传递到区间fib_num_sum[]就是区间Fibonacci数的和. 操作1

Wow! Such Sequence! HDU多校联合赛第三场1007

Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger from St. Beeze College. No, not cactuses. It's

【多校赛第三场】Redraw Beautiful Drawings【网络流】【谜のWA】

参考题解:http://blog.csdn.net/qian99/article/details/38276887 #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <queue> #include <vector> #include <algorithm>