A. Holiday Of Equality
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.

Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).

You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.

Input

The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.

The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.

Output

In the only line print the integer S — the minimum number of burles which are had to spend.

Examples
Input
5
0 1 2 3 4
Output
10
Input
5
1 1 0 1 1
Output
1
Input
3
1 3 1
Output
4
Input
1
12
Output
0
Note

In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.

In the second example it is enough to give one burle to the third citizen.

In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.

In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.

题意:n个数  增加最少的值使得n个数相等

题解;取n个数的最大值与每个数依次做差并求和输出

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
using namespace std;
int a[];
int main()
{
int n;
scanf("%d",&n);
int maxn=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
maxn=max(maxn,a[i]);
}
int ans=;
for(int i=;i<=n;i++)
{
ans=ans+(maxn-a[i]);
}
cout<<ans<<endl;
return ;
}
B. Blown Garland
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.

Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.

It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.

Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.

Input

The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:

  • 'R' — the light bulb is red,
  • 'B' — the light bulb is blue,
  • 'Y' — the light bulb is yellow,
  • 'G' — the light bulb is green,
  • '!' — the light bulb is dead.

The string s can not contain other symbols except those five which were described.

It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.

It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.

Output

In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.

Examples
Input
RYBGRYBGR
Output
0 0 0 0
Input
!RGYB
Output
0 1 0 0
Input
!!!!YGRB
Output
1 1 1 1
Input
!GB!RG!Y!
Output
2 1 1 0
Note

In the first example there are no dead light bulbs.

In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.

题意:要求连续的四个字符中必须只能有一个 ‘R’‘B’‘Y’‘G’

‘!’表示当前位置字符不确定 判断‘!’位置各个字符的个数并且输出

题解:正向遍历字符串,当遇到'!'时不断向前移动4位找到非‘!’的字符或者直到字符串结束

同理反向遍历字符串一次。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
using namespace std;
char a[];
int zha[];
map<char,int> mp;
int main()
{
scanf("%s",a);
int len=strlen(a);
for(int i=;i<len;i++)
{
if(a[i]=='!'&&zha[i]==)
{
int flag=i+;
while(flag<len)
{
if(a[flag]!='!'){
mp[a[flag]]++;
zha[i]=;
break;
}
flag+=;
}
}
}
for(int i=len-;i>=;i--)
{
if(a[i]=='!'&&zha[i]==)
{
int flag=i-;
while(flag>=)
{
if(a[flag]!='!'){
mp[a[flag]]++;
zha[i]=;
break;
}
flag-=;
}
}
}
printf("%d %d %d %d\n",mp['R'],mp['B'],mp['Y'],mp['G']);
return ;
}
C. Unfair Poll
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

Seating in the class looks like a rectangle, where n rows with m pupils in each.

The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...

The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.

During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.

If there is only one row in the class, then the teacher always asks children from this row.

Input

The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output

Print three integers:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.
Examples
Input
1 3 8 1 1
Output
3 2 3
Input
4 2 9 4 2
Output
2 1 1
Input
5 5 25 4 3
Output
1 1 1
Input
100 100 1000000000000000000 100 100
Output
101010101010101 50505050505051 50505050505051
Note

The order of asking pupils in the first test:

  1. the pupil from the first row who seats at the first table, it means it is Sergei;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the first row who seats at the third table;
  4. the pupil from the first row who seats at the first table, it means it is Sergei;
  5. the pupil from the first row who seats at the second table;
  6. the pupil from the first row who seats at the third table;
  7. the pupil from the first row who seats at the first table, it means it is Sergei;
  8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

  1. the pupil from the first row who seats at the first table;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the second row who seats at the first table;
  4. the pupil from the second row who seats at the second table;
  5. the pupil from the third row who seats at the first table;
  6. the pupil from the third row who seats at the second table;
  7. the pupil from the fourth row who seats at the first table;
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
  9. the pupil from the third row who seats at the first table;

题意:有n行m列学生,有一位老师在课上会问k个问题,在行上,是按照1,2。。。。n-1,n,n-1.。。。1这样的顺序提问,列操作上总是从第1列到第m列,对于每个输入询问,回答问题最多的学生回答了几次,最少的回答了几次,(x,y)位置上的同学回答了几次

题解:很明显这是一道模拟题,但是看到数据范围,我们肯定不能O(n)的模拟,所以我们先处理循环节,这是本题重点。一个循环节是从第1排一直到返回第一排(第一排只计算一次),对循环节取余数。对余数可以进行逐个模拟最多不超过20000次,可以接受。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
using namespace std;
ll n,m,k,x,y;
ll ans[][];
int main()
{
scanf("%I64d %I64d %I64d %I64d %I64d",&n,&m,&k,&x,&y);
ll exm=;
for(int i=; i<=n; i++)
exm+=m;
for(int i=; i<=n-; i++)
exm+=m;
for(int i=; i<=n-; i++)
{
for(int j=; j<=m; j++)
{
ans[i][j]+=*(k/exm);
}
}
for(int j=; j<=m; j++)
ans[][j]+=(k/exm);
if(n!=)
{
for(int j=; j<=m; j++)
ans[n][j]+=k/exm;
}
k=k%exm;
if(k!=)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
ans[i][j]++;
k--;
if(k==)
break;
}
if(k==)
break;
}
if(k!=){
for(int i=n-; i>=; i--)
{
for(int j=; j<=m; j++)
{
ans[i][j]++;
k--;
if(k==)
break;
}
if(k==)
break;
}
}
}
ll ans1=,ans2=+;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
ans1=max(ans1,ans[i][j]);
ans2=min(ans2,ans[i][j]);
}
}
cout<<ans1<<" "<<ans2<<" "<<ans[x][y]<<endl;
return ;
}

Codeforces Round #392 (Div. 2) A B C 水 模拟 暴力的更多相关文章

  1. Codeforces Round #376 (Div. 2) A B C 水 模拟 并查集

    A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心

    A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...

  3. Codeforces Round #277 (Div. 2) A B C 水 模拟 贪心

    A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...

  4. Codeforces Round #370 (Div. 2) A B C 水 模拟 贪心

    A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  6. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  7. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  8. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  9. Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

随机推荐

  1. 1.1.0 Unity零基础入门2——Roll a Ball

    1. 游戏界面 2.代码 //FoodRotate - - 控制cube旋转 using System.Collections; using System.Collections.Generic; u ...

  2. vuex -- vue的状态管理模式

    Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 状态管理模式.集中式存储管理 一听就很高大 ...

  3. leetcode-二进制手表

    二进制手表顶部有 4 个 LED 代表小时(0-11),底部的 6 个 LED 代表分钟(0-59). 每个 LED 代表一个 0 或 1,最低位在右侧. 例如,上面的二进制手表读取 “3:25”. ...

  4. leetcode-位1的个数(位与运算)

    位1的个数 编写一个函数,输入是一个无符号整数,返回其二进制表达式中数字位数为 ‘1’ 的个数(也被称为汉明重量). 示例 : 输入: 11 输出: 3 解释: 整数 11 的二进制表示为 00000 ...

  5. 关于java中的“error: bad operand types for binary operator ”

    今天做这个题目的时候(142. O(1) Check Power of 2),遇到一个错误“ bad operand types for binary operator '&' ”. 先贴一下 ...

  6. 数据库Mysql的学习(三)-各种约束

    删除数据库表 drop table [if exists] 表一,表二.....; 表分区:比如图书信息表有1000万个图书信息,如何优化他,其中一种方式就是表分区.就是把一张表的数据分成多个区块,这 ...

  7. Kali渗透测试工具-netcat

    netcat被称作是网络工具当中的瑞士军刀,短小却功能强大 1.端口扫描 nc -nvz 目标IP 端口范围 eg: nc -nvz 192.168.1.105 1-65535 -n参数是不要使用DN ...

  8. 冲刺ing-1

    冲刺一 1.第一天的工作分配: 姓名 任务分工 吴伟华(队长) 布置团队任务,发表汇总博客及第一次冲刺博客 蔺皓雯 讨论任务分配 杨池宇 讨论任务分配 鲁婧楠 讨论任务分配 曾茜 讨论任务分配 蔡晨旸 ...

  9. Tomcat服务器学习和使用(一)

    一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件. 如果想修改Tomcat服务器的启动端口,则可以在server.xml ...

  10. python2 对URL编码进行编译

    在请求页面时有时会返回类似: %E8%AF%A5985%E5%A4%A7%E5%AD%A6%E5%B8%B8%E5%B9%B4%E4%BD%8D%E5%B1%85%E5%9B%BD%E5%86%85% ...