A. Initial Bet
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.

Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins b in the initial bet.

Input

The input consists of a single line containing five integers c1, c2, c3, c4 and c5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0 ≤ c1, c2, c3, c4, c5 ≤ 100).

Output

Print the only line containing a single positive integer b — the number of coins in the initial bet of each player. If there is no such value ofb, then print the only value "-1" (quotes for clarity).

Examples
input
2 5 4 0 4
output
3
input
4 5 9 2 1
output
-1
Note

In the first sample the following sequence of operations is possible:

  1. One coin is passed from the fourth player to the second player;
  2. One coin is passed from the fourth player to the fifth player;
  3. One coin is passed from the first player to the third player;
  4. One coin is passed from the fourth player to the second player.

题意:求整数平均数,并且平均数>0;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
const ll INF=1e18+;
int main()
{
int sum=;
for(int i=;i<=;i++)
{
int x;scanf("%d",&x),sum+=x;
}
if(sum%||sum==)
printf("-1\n");
else
printf("%d\n",sum/);
return ;
}
B. Random Teams
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.

Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

Input

The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively.

Output

The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.

Examples
input
5 1
output
10 10
input
3 2
output
1 1
input
6 3
output
3 6
Note

In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.

In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.

In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.

题意:n个人,m支队,将n个人分到m支队,每个队最少一个人,每个队内的人相互认识,但是不认识别的队的人,求分配认识对数,最小和最大;

思路:最小显然平均分配,最大显然是将(m-1)支队分到一个人,另外一只分n-m+1个人;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
const ll INF=1e18+;
ll getans(ll x)
{
return x*(x-)/;
}
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
ll minn=getans(n/m+(n%m?:))*(n%m?n%m:m)+getans(n/m)*((m-(n%m))%m);
ll maxx=getans(n-m+);
printf("%lld %lld\n",minn,maxx);
return ;
}
C. Table Decorations
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?

Your task is to write a program that for given values rg and b will find the maximum number t of tables, that can be decorated in the required manner.

Input

The single line contains three integers rg and b (0 ≤ r, g, b ≤ 2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.

Output

Print a single integer t — the maximum number of tables that can be decorated in the required manner.

Examples
input
5 4 3
output
4
input
1 1 1
output
1
input
2 3 3
output
2
Note

In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.

题意:有r个红气球,g个绿气球,b个蓝气球,每张桌子的三个气球不能同色,问r,g,b最多能装多少张桌子;

思路:贪心,判断是否有极端,否则相加除3;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
const ll INF=1e18+;
ll a[];
int main()
{
scanf("%lld%lld%lld",&a[],&a[],&a[]);
sort(a,a+);
if(a[]>*a[]+*a[])
printf("%lld\n",a[]+a[]);
else
printf("%lld\n",(a[]+a[]+a[])/);
return ;
}

最新文章

  1. 借助91助手,将ibook中的pdf文件拷贝至其它的pdf阅读器中(ios设备无需越狱)
  2. rhel7网络管理
  3. RCA端子颜色(红、白、黄)
  4. CDH中,执行HIVE脚本表联查权限问题。。
  5. 响应式架构:消息模式Actor实现与Scala、Akka应用集成
  6. javascript 中文数字阿拉伯数字转换类 Nzh
  7. Java [Leetcode 202]Happy Number
  8. Dubbo实例
  9. The Painter&#39;s Partition Problem Part II
  10. leaflet地图库
  11. unity3d继续尝试
  12. ABP+AdminLTE+Bootstrap Table aspnetboilerplate 学习
  13. 结合JDK源码看设计模式——桥接模式
  14. Nginx使用教程(四):提高Nginx网络吞吐量之buffers优化
  15. 机器学习基石笔记:05 Training versus Testing
  16. Mac下在Shell终端下使用open快速打开窗口文件夹
  17. 添加javabrowser 支持中文
  18. C#计算时间间隔的方法小结
  19. C# 类型初始化(Type initialization)
  20. MFC中改变控件的大小和位置(zz)

热门文章

  1. php后门管理工具weevely
  2. httpclient设置proxy与proxyselector
  3. windows下在Eclipse中启动的tomcat没有乱码,单独部署到tomcat下乱码解决方案
  4. 距离,margin padding ,width height 用法 ,记录
  5. Java线程的5种状态及切换
  6. spring 登录提示 Bad credentials
  7. python read文件的r和rb的区别
  8. Python 函数名作为字典值
  9. 2015/7/29 (高开,V形反转,各种指标背离——可惜没买进,填补空缺图形的心理分析)
  10. ES集群性能调优链接汇总