Codeforces Round #540 (Div. 3) A. Water Buying

由于2是1的倍数,所以直接判断2的是否比2 * 1的便宜,便宜先买2,否则只买1

#include
#define ll  long long
using namespace std;

int main()
{
    int T;
    scanf("%d", &T);
    while(T --)
    {
        ll n, a, b;
        scanf("%lld %lld %lld", &n, &a, &b);
        ll ans = 0;
        if(a * 2 <= b)
        {
            ans = n * a;
        }
        else
        {
            ll temp = n / 2;
            ans = temp * b;
            n -= temp * 2;
            ans += a * n;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

 

你可能感兴趣的:(Codeforces Round #540 (Div. 3) A. Water Buying)