A - Restoring Three Numbers CodeForces - 1154A

Polycarp has guessed three positive integers aa, bb and cc. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+ba+b, a+ca+c, b+cb+c and a+b+ca+b+c.

You have to guess three numbers aa, bb and cc using given numbers. Print three guessed integers in any order.

Pay attention that some given numbers aa, bb and cc can be equal (it is also possible that a=b=ca=b=c).

Input

The only line of the input contains four positive integers x1,x2,x3,x4x1,x2,x3,x4 (2≤xi≤1092≤xi≤109) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number x1,x2,x3,x4x1,x2,x3,x4.

Output

Print such positive integers aa, bb and cc that four numbers written on a board are values a+ba+b, a+ca+c, b+cb+c and a+b+ca+b+c written in some order. Print aa, bb and cc in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.

Examples

Input
3 6 5 4
Output
2 1 3
Input
40 40 40 60
Output
20 20 20
Input
201 101 101 200
Output
1 100 100
题意:给你四个值,代表a+b,a+c,b+c,a+b+c的值,然后让你找到a,b,c的值。
解法:排完序之后,a+b+c肯定是最大的,那么减去前三个值也就是得到a,b,c的值了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=;
int x[maxn];
int a,b,c;
int main()
{
for(int i=;i<;i++)
scanf("%d",&x[i]);
sort(x,x+);
a=x[]-x[];
b=x[]-x[];
c=x[]-x[];
printf("%d %d %d\n",a,b,c);
return ;
}

B - Make Them Equal CodeForces - 1154B

You are given a sequence a1,a2,…,ana1,a2,…,an consisting of nn integers.

You can choose any non-negative integer DD (i.e. D≥0D≥0), and for each aiai you can:

  • add DD (only once), i. e. perform ai:=ai+Dai:=ai+D, or
  • subtract DD (only once), i. e. perform ai:=ai−Dai:=ai−D, or
  • leave the value of aiai unchanged.

It is possible that after an operation the value aiai becomes negative.

Your goal is to choose such minimum non-negative integer DD and perform changes in such a way, that all aiai are equal (i.e. a1=a2=⋯=ana1=a2=⋯=an).

Print the required DD or, if it is impossible to choose such value DD, print -1.

For example, for array [2,8][2,8] the value D=3D=3 is minimum possible because you can obtain the array [5,5][5,5] if you will add DD to 22 and subtract DD from 88. And for array [1,4,7,7][1,4,7,7] the value D=3D=3 is also minimum possible. You can add it to 11 and subtract it from 77 and obtain the array [4,4,4,4][4,4,4,4].

Input

The first line of the input contains one integer nn (1≤n≤1001≤n≤100) — the number of elements in aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100) — the sequence aa.

Output

Print one integer — the minimum non-negative integer value DD such that if you add this value to some aiai, subtract this value from some aiai and leave some aiai without changes, all obtained values become equal.

If it is impossible to choose such value DD, print -1.

Examples

Input
6
1 4 4 7 4 1
Output
3
Input
5
2 2 5 2 5
Output
3
Input
4
1 3 3 7
Output
-1
Input
2
2 8
Output
3
题意:给你n个数,找到一个数D,对于这n个数的每一个有三种操作,ai+D,ai-D,ai。问最后能不能使得这n个数相等,可以的D中取最小值。
解法:数组排序去重之后,判断剩下的数不重复的值有几个,超过三个的话就肯定不存在这个D值了,如果是三个的话只有是等比数列的时候才可以;如果是两个的话,看这两个数相加起来是否为偶数,是偶数就能使得一个数+D,一个数-D
得到两个相等的数值,奇数的话只能把一个数变为另一个数;如果全相等的话就输出0即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=;
int n;
int a[maxn];
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int len=unique(a,a+n)-a;
if(len==)
printf("0\n");
else if(len==)
{
if((a[]-a[])% == )
printf("%d\n",(a[]-a[])/);
else if((a[]-a[])% == )
printf("%d\n",a[]-a[]);
}
else if(len==&&a[]-a[]==a[]-a[])
printf("%d\n",a[]-a[]);
else
printf("-1\n");
return ;
}

C - Gourmet Cat CodeForces - 1154C

Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food:

  • on Mondays, Thursdays and Sundays he eats fish food;
  • on Tuesdays and Saturdays he eats rabbit stew;
  • on other days of week he eats chicken stake.

Polycarp plans to go on a trip and already packed his backpack. His backpack contains:

  • aa daily rations of fish food;
  • bb daily rations of rabbit stew;
  • cc daily rations of chicken stakes.

Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

Input

The first line of the input contains three positive integers aa, bb and cc (1≤a,b,c≤7⋅1081≤a,b,c≤7⋅108) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.

Output

Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.

Examples

Input
2 1 1
Output
4
Input
3 2 2
Output
7
Input
1 100 1
Output
3
Input
30 20 10
Output
39

思路:一星期a有3次,b有2次,c有2次,所以依次相除,在选取最小表示最多坚持完整的星期有几个,之后枚举判断一星期之内(不包含7)的最多坚持天数相加即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=;
int a,b,c;
int ans=;
int main()
{
scanf("%d %d %d",&a,&b,&c);
while()
{
if(a<=||b<=||c<=)
break;
a-=;
b-=;
c-=;
ans+=;
}
int temp=;
for(int i=;i<=;i++)
{
int t=i;
int maxx=;
int aa=a,bb=b,cc=c;
while(true)
{
if(aa<||bb<||cc<)
{
temp=max(temp,maxx);
break;
}
if(t%==||t%==||t%==)
aa--;
if(t%==||t%==)
bb--;
if(t%==||t%==)
cc--;
t++;
maxx++;
}
}
printf("%d\n",ans+temp-);
return ;
}

CF #552 div3的更多相关文章

  1. CF #552(div3)G 最小lcm

    题目链接:http://codeforces.com/contest/1154/problem/G 题意:lcm是最小公倍数,本题就是给你一个数组(可能会重复),要求你判断出那两个数的最小公倍数最小, ...

  2. CF #552(div3)F 背包问题

    题目链接:http://codeforces.com/contest/1154/problem/F 题意:一个商店有n个物品,每个物品只能买一次,同时有m种优惠,即一次买够x件后,这x件中最便宜的k件 ...

  3. CF #575 Div3

    // 比赛链接:https://codeforces.com/contest/1196 // CF 2019.7.24 // 本想Div3手速场上分,结果卡在C题,掉了不少分. // 自闭了这么久,今 ...

  4. CF 552(div 3) E Two Teams 线段树,模拟链表

    题目链接:http://codeforces.com/contest/1154/problem/E 题意:两个人轮流取最大值与旁边k个数,问最后这所有的数分别被谁给取走了 分析:看这道题一点思路都没有 ...

  5. CF 552 Neko does Maths

    给出两个数a,b 求k     使得 a+k b+k有最小公倍数 a,b同时加上一个非负整数k,使得,a+k,b+k的最小公倍数最小 因为最小公公倍数=x*y / gcd(x,y),所以肯定离不开最大 ...

  6. 2021-01-25 cf #697 Div3 C题(超时,换思路减少复杂度)

    题目链接:https://codeforces.com/contest/1475/problem/C 题意要求:需组成的2对,男的序号不能重,女的序号不能重 比如这例 输入: 行1--测试个数 行1` ...

  7. 12.27 cf div3 解题报告

    12.27 cf div3 解题报告 wxy.wxy,带上分拉,全场做了个无脑小白 比赛场地 A: T1,跟着模拟就好了 B: sort一遍之后 去除的数一定是a[1]或者a[n] 比较去除谁小就输出 ...

  8. CF contest 1216 Div3. F

    题目链接:Click here Solution: 看起来是贪心,其实不然... 我们定义\(f[i]\)表示仅覆盖\(1\sim i\)所需要的最小代价,那么对\(i\)为0的点来说,易得\(f[i ...

  9. CF 552C 进制转换

    http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...

随机推荐

  1. 理解JavaScript中的深拷贝和浅拷贝

    , num2 = num1;console.log(num1) //1console.log(num2) //1num2 = 2; //修改num2console.log(num1) //1conso ...

  2. 洛谷P4822 冻结

    题目描述 "我要成为魔法少女!" "那么,以灵魂为代价,你希望得到什么?" "我要将有关魔法和奇迹的一切,封印于卡片之中„„" 在这个愿望被 ...

  3. Python模块之re

    re模块 准备: flags有很多可选值: re.I(IGNORECASE)忽略大小写,括号内是完整的写法 re.M(MULTILINE)多行模式,改变^和$的行为 re.S(DOTALL)点可以匹配 ...

  4. Selenium 开源书(一): Selenium历史

    Selenium历史 Selenium最初由Jason Huggins于2004年开发,作为ThoughtWorks的内部工具.Huggins后来加入了ThoughtWorks的其他程序员和测试人员, ...

  5. SpringBoot---Web开发

    一.概述 1.SpringBoot提供了spring-boot-starter-web为 web开发 予以支持: 2.spring-boot-starter-web提供了 内嵌的Tomcat 以及 S ...

  6. 《springcloud 五》springcloud stream

    什么是消息驱动? SpringCloud Stream消息驱动可以简化开发人员对消息中间件的使用复杂度,让系统开发人员更多尽力专注与核心业务逻辑的开发.SpringCloud Stream基于Spri ...

  7. jquery的$().each和$.each的区别

    在jquery中,遍历对象和数组,经常会用到$().each和$.each(),两个方法.两个方法是有区别的,从而这两个方法在针对不同的操作上,显示了各自的特点. $().each,对于这个方法,在d ...

  8. 在MVC中使用dotless后台动态解析LESSCSS的学习笔记

    通过学习LessCSS,我们知道,Less是需要通过编译才能生成 .css 文件,主要使用三种方式进行编译: 1)使用第三方编译工具,在项目发布前编译好放在项目中. 2)在浏览器端解析执行,需要引用  ...

  9. springboot项目实现批量新增功能

    这个困扰我一整天东西,终于解决了. 首先是mybatis中的批量新增sql语句. 注意:这里我给的是我需要新增的字段,你们改成你们需要的字段. <insert id="insertBa ...

  10. linux 安装jdk (二进制文件安装)

    1.下载jdk 此处以1.7 为例 :jdk-7u79-linux-x64.tar.gz 2.通过ssh将安装介质传到服务器 我一般放在 /opt 目录下 3.用tar 命令解压缩   tar -zx ...