CF912A Tricky Alchemy

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<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#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-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> 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;
}

猜你喜欢

转载自www.cnblogs.com/zxyqzy/p/10123496.html