Problem
http://codeforces.com/contest/912/problem/A
Analysis
One needs 2·x + y yellow and 3·z + y blue crystals. The answer therefore is max(0, 2·x + y - A) + max(0, 3·z + y - B).
Code
C++
#include <iostream>
using namespace std;
int main()
{
long long A, B;
long long x, y, z;
cin >> A >> B;
cin >> x >> y >> z;
long long yellow = 2 * x + y - A;
long long blue = y + 3 * z - B, 0LL;
cout << max(yellow, 0) + max(blue, 0);
return 0;
}
Python2
a, b = map(int, raw_input().split())
x, y, z = map(int, raw_input().split())
yellow = 2 * x + y
blue = y + 3 * z
ans = max(0, yellow - a) + max(0, blue - b)
print ans
更多内容请关注微信公众号