Codeforces Round #456 Div.2 A. Tricky Alchemy

本文解析了CodeForces竞赛中一道A级题目,通过分析题目需求,给出了使用C++和Python实现的代码示例。重点在于计算所需黄色和蓝色水晶的数量,并确保数量不超过给定限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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



更多内容请关注微信公众号
wechat.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值