【43.26%】【codeforces 732C】Sanatorium
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 b, d 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.
【题解】
原本以为是很复杂的分类讨论问题;
推了下
a>=b>=c
a>=c>=b
b>=a>=c之后
设最大的数为a,其他两个数无所谓为b和c;
发现答案都是max(a-1,b)-b+max(a-1,c)-c;
然后就大胆的排序贪心下;
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
LL a[4];
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%I64d%I64d%I64d",&a[1],&a[2],&a[3]);
sort(a + 1, a + 1 + 3);
LL ans;
ans = max(a[3] - 1, a[2]) - a[2] + max(a[3] - 1, a[1]) - a[1];
printf("%I64d\n", ans);
return 0;
}
【43.26%】【codeforces 732C】Sanatorium的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【26.83%】【Codeforces Round #380C】Road to Cinema
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【41.43%】【codeforces 560C】Gerald's Hexagon
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【26.09%】【codeforces 579C】A Problem about Polyline
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【26.67%】【codeforces 596C】Wilbur and Points
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【30.43%】【codeforces 746C】Tram
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.26%】【codeforces 747D】Winter Is Coming
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 797C】Minimal string
[题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...
- 【codeforces 510C】Fox And Names
[题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...
随机推荐
- iOS_03_关键字、标识符、注释
一.学习语法之前的提醒 1. C语言属于一门高级语言,其实,所有高级语言的基本语法组成部分都一样,只是表现形式不太一样. 2. 就好像亚洲人和非洲人,大家都有人类的结构:两只手.两只脚.一个头,只是他 ...
- 硬件——STM32,ADC篇
未完,待续...... 也就是stm32f10X系列的adc采集出来的结果是12位的 stm32f10X系列有两个16位adc 关于程序的编写方法:一般 “某某.c文件”:都是用来设置“某某”的一些 ...
- ES6的基础知识总结
一. ES6 ES6中定义变量使用 let/const let 使用let定义的变量不能进行"变量提升" 同一个作用域中,let不能重复定义相同的变量名 使用var在全局作用域中定 ...
- 【Android工具类】验证码倒计时帮助类CountDownButtonHelper的实现
转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 我们在做有关短信验证码功能的时候.为了防止用户无休止的获取短信验证码,或者是误操作.造成验证码混乱的情况.我 ...
- vue指令概览
原文 简书原文:https://www.jianshu.com/p/5fd47b7422fd 大纲 1.什么是vue指令 2.向指令中传入参数 3.指令中带入修饰符 4.指令的缩写 5.常见的vue指 ...
- HDU 1251统计难题 字典树
字典树的应用. 数据结构第一次课的作业竟然就需要用到树了!!!这不科学啊.赶紧来熟悉一下字典树. 空间开销太大T T #include<cstdio> #include<cstrin ...
- 【BZOJ 2119】股市的预测
[链接]h在这里写链接 [题意] 给你一个长度为n的数组a[] 设b[i] = a[i+1]-a[i]; 然后让你在b[i]里面找ABA的形式. 这里B的长度要求为m; ...
- bow lsa plsa
Bag-of-Words (BoW) 模型是NLP和IR领域中的一个基本假设.在这个模型中,一个文档(document)被表示为一组单词(word/term)的无序组合,而忽略了语法或者词序的部分.B ...
- 动态布局Cell的高度
1 自定义Cell, 在Cell的构造方法里面添加好所有的子控件 2 3 2 在HeightForRowAtIndexPath方法中返回每一行Cell对应的高度 4 5 3 在Cell的layoutS ...
- thinkphp5项目--企业单车网站(八)(文章板块要点)(删除图片)
thinkphp5项目--企业单车网站(八)(文章板块要点)(删除图片) 项目地址 fry404006308/BicycleEnterpriseWebsite: Bicycle Enterprise ...