博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF912A Tricky Alchemy
阅读量:6453 次
发布时间:2019-06-23

本文共 3367 字,大约阅读时间需要 11 分钟。

A. Tricky Alchemy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.

Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.

Right now there are A yellow and B blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.

Input

The first line features two integers A and B (0 ≤ A, B ≤ 109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.

The next line contains three integers x, y and z (0 ≤ x, y, z ≤ 109) — the respective amounts of yellow, green and blue balls to be obtained.

Output

Print a single integer — the minimum number of crystals that Grisha should acquire in addition.

Examples
Input
Copy
4 3 2 1 1
Output
Copy
2
Input
Copy
3 9 1 1 3
Output
Copy
1
Input
Copy
12345678 87654321 43043751 1000000000 53798715
Output
Copy
2147483648
Note

In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#pragma GCC optimize(2)using namespace std;#define maxn 300005#define inf 0x3f3f3f3f#define INF 9999999999#define rdint(x) scanf("%d",&x)#define rdllt(x) scanf("%lld",&x)#define rdult(x) scanf("%lu",&x)#define rdlf(x) scanf("%lf",&x)#define rdstr(x) scanf("%s",x)typedef long long ll;typedef unsigned long long ull;typedef unsigned int U;#define ms(x) memset((x),0,sizeof(x))const long long int mod = 1e9 + 7;#define Mod 1000000000#define sq(x) (x)*(x)#define eps 1e-3typedef pair
pii;#define pi acos(-1.0)const int N = 1005;#define REP(i,n) for(int i=0;i<(n);i++)typedef pair
pii;inline ll rd() { ll x = 0; char c = getchar(); bool f = false; while (!isdigit(c)) { if (c == '-') f = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f ? -x : x;}ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b);}ll sqr(ll x) { return x * x; }/*ll ans;ll exgcd(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1; y = 0; return a; } ans = exgcd(b, a%b, x, y); ll t = x; x = y; y = t - a / b * y; return ans;}*/ll qpow(ll a, ll b, ll c) { ll ans = 1; a = a % c; while (b) { if (b % 2)ans = ans * a%c; b /= 2; a = a * a%c; } return ans;}int main(){ //ios::sync_with_stdio(0); ll a, b, x, y, z; rdllt(a); rdllt(b); rdllt(x); rdllt(y); rdllt(z); ll w1 = 2 * x + y - a; ll w2 = y + 3 * z - b; if (w1 > 0 && w2 > 0)cout << w1 + w2 << endl; else if (w1 > 0 && w2 <= 0)cout << w1 << endl; else if (w2 > 0 && w1 <= 0)cout << w2 << endl; else cout << 0 << endl; return 0;}

 

转载于:https://www.cnblogs.com/zxyqzy/p/10123496.html

你可能感兴趣的文章
操作系统os常识
查看>>
乱码的情况
查看>>
虚拟机centos 同一个tomcat、不同端口访问不同的项目
查看>>
在不花一分钱的情况下,如何验证你的创业想法是否可行?《转》
查看>>
Linux/Android 性能优化工具 perf
查看>>
learn go recursive
查看>>
GitHub使用教程、注册与安装
查看>>
论以结果为导向
查看>>
CODE[VS] 1294 全排列
查看>>
<<The C Programming Language>>讀書筆記
查看>>
如何在目录中查找具有指定字符串的文件(shell)
查看>>
安卓学习笔记2
查看>>
选择排序
查看>>
DotNet(C#)自定义运行时窗体设计器 一
查看>>
P2627 修剪草坪[dp][单调队列]
查看>>
JS详细入门教程(上)
查看>>
Android学习笔记21-ImageView获取网络图片
查看>>
线段树分治
查看>>
git代码冲突
查看>>
lnmp1.3 配置pathinfo---thinkphp3.2 亲测有效
查看>>