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
  1. 3 2 1
output
  1. 1
input
  1. 1 0 0
output
  1. 0
input
  1. 1 1 1
output
  1. 0
input
  1. 1000000000000000000 0 1000000000000000000
output
  1. 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.

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

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <cstring>
  8. #include <string>
  9. #include <set>
  10. #include <map>
  11. #include <queue>
  12. #include <stack>
  13. #include <vector>
  14. #include <list>
  15. #define rep(i,m,n) for(i=m;i<=n;i++)
  16. #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
  17. #define mod 1000000007
  18. #define inf 0x3f3f3f3f
  19. #define llinf 0x3f3f3f3f3f3f3f3fLL
  20. #define vi vector<int>
  21. #define pb push_back
  22. #define mp make_pair
  23. #define fi first
  24. #define se second
  25. #define ll long long
  26. #define pi acos(-1.0)
  27. #define pii pair<int,int>
  28. #define Lson L, mid, ls[rt]
  29. #define Rson mid+1, R, rs[rt]
  30. #define sys system("pause")
  31. const int maxn=2e5+;
  32. using namespace std;
  33. ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
  34. ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
  35. inline ll read()
  36. {
  37. ll x=;int f=;char ch=getchar();
  38. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  39. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  40. return x*f;
  41. }
  42. int n,m,k,t;
  43. ll a[],ans,ma;
  44. int main()
  45. {
  46. int i,j;
  47. rep(i,,)scanf("%lld",&a[i]),ma=max(ma,a[i]);
  48. rep(i,,)if(a[i]<ma)ans+=ma--a[i];
  49. printf("%lld\n",ans);
  50. //system("Pause");
  51. return ;
  52. }

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. Sass入门:第四章

    1.加法 加法运算是Sass中运算的一种,在变量或属性中都可以做加法运算.如: .box { width: 20px + 8in; } 编译出来的CSS: .box { width: 788px; } ...

  2. Linux入门(二)Linux基本命令及基本操作

    1 常用Linux命令 图形界面进入到字符界面: ctrl+alt+F2~F6 字符界面进入到图形界面:ctrl +alt+F7 查看本机ip:  ifconfig  (windows是:ipconf ...

  3. xlrd doc

    The xlrd Module A Python module for extracting data from MS Excel ™ spreadsheet files. Version 0.7.3 ...

  4. CF 604B More Cowbell#贪心

    (- ̄▽ ̄)-* //把最大单独放,然后第二大的和最小的放一起,第三大的和第二小的放一起 //由此类推,求最大值,即为盒的最小值 #include<iostream> #include&l ...

  5. jbpm4.3表结构和表字段说明

    整体说明: JBPM4_DEPLOYMENT   流程定义表JBPM4_DEPLOYPROP 流程定义属性表 JBPM4_EXECUTION  流程实例表JBPM4_HIST_ACTINST 流程活动 ...

  6. Android应用测试性能的工具Emmagee,导出文件格式问题分析

    原文引用自:http://www.open-open.com/lib/view/open1367026451078.html Emmagee是监控指定被测应用在使用过程中占用机器的CPU.内存.流量资 ...

  7. Urbanization

    Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. iOS UIScrollview代理方法

    方法&&属性: // 监控目前滚动的位置(默认CGPointZero) CGPoint contentOffset; - (void)setContentOffset:(CGPoint ...

  9. java 文件的基本操作

    1 /** * java 文件操作 * 2016/5/10 **/ package cn.Java_7; import java.io.*; import java.util.Scanner; imp ...

  10. 河南多校联合训练 南阳理工 1261 音痴又音痴的LT

    描述 LT最近一直在无限循环薛之谦的歌,简直都中毒了!可是呢…他的歌LT还是不会唱(其实不止他的歌LT不会唱,所有人的歌LT都不会唱…因为LT是标准的音痴)可是LT又很喜欢唱歌(所以LT不仅是音痴还是 ...