Sanatorium
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!

Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.

Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.

According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.

Input

The only line contains three integers bd and s (0 ≤ b, d, s ≤ 1018,  b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.

Output

Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.

Examples
input
3 2 1
output
1
input
1 0 0
output
0
input
1 1 1
output
0
input
1000000000000000000 0 1000000000000000000
output
999999999999999999
Note

In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.

In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.

In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.

分析:贪心,哪个最大,就以哪个开始到,然后模拟;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fLL
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t;
ll a[],ans,ma;
int main()
{
int i,j;
rep(i,,)scanf("%lld",&a[i]),ma=max(ma,a[i]);
rep(i,,)if(a[i]<ma)ans+=ma--a[i];
printf("%lld\n",ans);
//system("Pause");
return ;
}

Sanatorium的更多相关文章

  1. Codeforces Round #377 (Div. 2) C. Sanatorium 水题

    C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. CodeForces 732C Sanatorium

    C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. 【43.26%】【codeforces 732C】Sanatorium

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. CodeForces 732C Sanatorium (if-else)

    题意:某人去旅游,记录了一共吃了多少顿饭,早中晚,但是有可能缺少,问你最少缺少了多少顿. 析:每把三个数排序,然后再一一对比,肯定是以最大数为主,其他两个肯定是缺少了. 代码如下: #pragma c ...

  5. codeforces 732

    A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces Round #377 (Div. 2) A B C D 水/贪心/贪心/二分

    A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  7. codeforces732C

    Sanatorium CodeForces - 732C Vasiliy spent his vacation in a sanatorium, came back and found that he ...

  8. Codeforces Round #377 (Div. 2)A,B,C,D【二分】

    PS:这一场真的是上分场,只要手速快就行.然而在自己做的时候不用翻译软件,看题非常吃力非常慢,还有给队友讲D题如何判断的时候又犯了一个毛病,一定要心平气和,比赛也要保证,不要用翻译软件做题: Code ...

  9. Codeforces Round #377 (Div. 2)部分题解A+B+C!

    A. Buy a Shovel 题意是很好懂的,一件商品单价为k,但他身上只有10块的若干和一张r块的:求最少买几件使得不需要找零.只需枚举数量判断总价最后一位是否为0或r即可. #include&l ...

随机推荐

  1. Node.js:服务器与数据流

    1.Node 常被用来构建服务器,下面代码就是创建了一个服务器. var http = require('http'); var server = http.createServer(); serve ...

  2. C#字符串转INT

    Convent.ToInt32(string ) 可以转化字符串   其他 * .tostring();   (int ) char //强制类型转换 不能转化字符串

  3. Linux vim编辑器

    1.工作模式 命令模式(a,i,o等键)——>输入模式 输入模式(Esc键)——>命令模式 命令模式(:键)——>末行模式 末行模式(Esc键)——>命令模式 2.vim使用命 ...

  4. storm.yaml 配置项

    配置项 配置说明 storm.zookeeper.servers ZooKeeper服务器列表 storm.zookeeper.port ZooKeeper连接端口 storm.local.dir s ...

  5. [转]整理jquery开发技巧

    1.创建一个嵌套的过滤器   1.$(jquery).filter(":not(:has(.selected))") //去掉所有不包含class为.selected的元素 2.使 ...

  6. NOIP2010-普及组复赛模拟试题-第一题-手机

    题目背景 Background 现在手机使用越来越广泛了  题目描述 Description 一般的手机的键盘是这样的:   要按出英文字母就必须要按数字键多下.例如要按出 x 就得按 9 两下,第一 ...

  7. jQuery控制表格行移动,序号不变

    @model Gd.NetSign.Controllers.DTO.SysPamaterDTO @{ ViewBag.Title = "SysPamatList"; //Layou ...

  8. Swift-HELP

    //获取网页地址对应的字符串 var urlString = url.absoluteURL.absoluteString

  9. genymotion模拟器配置X86模拟器加速器

    网上下载zip包 http://download.csdn.net/download/we5868123/9430140 直接拖进去即可,虚拟机不能使用管理员权限启动 名字为:解决genymotion ...

  10. python中的矩阵运算

    摘自:http://m.blog.csdn.net/blog/taxueguilai1992/46581861 python的numpy库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入nu ...