Water Buying
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp wants to cook a soup. To do it, he needs to buy exactly nn liters of water.

There are only two types of water bottles in the nearby shop — 11 -liter bottles and 22 -liter bottles. There are infinitely many bottles of these two types in the shop.

The bottle of the first type costs aa burles and the bottle of the second type costs bb burles correspondingly.

Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly nn liters of water in the nearby shop if the bottle of the first type costs aa burles and the bottle of the second type costs bb burles.

You also have to answer qq independent queries.

Input

The first line of the input contains one integer qq (1≤q≤5001≤q≤500 ) — the number of queries.

The next nn lines contain queries. The ii -th query is given as three space-separated integers nini , aiai and bibi (1≤ni≤1012,1≤ai,bi≤10001≤ni≤1012,1≤ai,bi≤1000 ) — how many liters Polycarp needs in the ii -th query, the cost (in burles) of the bottle of the first type in the ii -th query and the cost (in burles) of the bottle of the second type in the ii -th query, respectively.

Output

Print qq integers. The ii -th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly nini liters of water in the nearby shop if the bottle of the first type costs aiai burles and the bottle of the second type costs bibi burles.

Input

4
10 1 3
7 3 2
1 1000 1
1000000000000 42 88
Output
10
9
1000
42000000000000
 #include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
int main(int argc, char const *argv[])
{
int n;
cin>>n;
ll k,a,b;
for( int i=; i<n; i++ ){
cin>>k>>a>>b;
if(a*<=b) cout<<k*a<<endl;
else{
if(k%==) cout<<k/*b<<endl;
else cout<<k/*b+a<<endl;
}
}
return ;
}

Water Buying的更多相关文章

  1. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

  2. [LeetCode] Pacific Atlantic Water Flow 太平洋大西洋水流

    Given an m x n matrix of non-negative integers representing the height of each unit cell in a contin ...

  3. [LeetCode] Trapping Rain Water II 收集雨水之二

    Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...

  4. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  5. [LeetCode] Trapping Rain Water 收集雨水

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  6. [LeetCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  7. 如何装最多的水? — leetcode 11. Container With Most Water

    炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...

  8. 【leetcode】Container With Most Water

    题目描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...

  9. [LintCode] Trapping Rain Water 收集雨水

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

随机推荐

  1. 卷积的三种模式:full, same, valid

    通常用外部api进行卷积的时候,会面临mode选择. 本文清晰展示三种模式的不同之处,其实这三种不同模式是对卷积核移动范围的不同限制. 设 image的大小是7x7,filter的大小是3x3 1,f ...

  2. bootstrap-3-验证表单

    js: $('#nqs-add-userxinxi-form').bootstrapValidator({ message: 'This value is not valid', excluded : ...

  3. 《闲聊 ASP.NET Core》系列直播清单

    [闲聊 ASP.NET Core]第一期:项目与应用结构 [闲聊 ASP.NET Core]第二期:Web Host 初始化与生命周期事件 [闲聊ASP.NET Core]第三期:应用程序配置 [闲聊 ...

  4. ionic andorid apk 签名, 查看签名MD5

    ionic cordova build android生成的是带签名的android-debug.apk, 这个是可以在手机上安装的, 但是换个电脑打包这个签名就不一样了, 这样就不能直接替换安装了, ...

  5. POSIX 线程的创建与退出

    前言 创建线程: pthread_create() 退出线程: pthread_exit()return pthread_cancel() 线程的创建 使用多线程,首先就需要创建一个新线程.那么线程是 ...

  6. docker 命令集

    1.提交本地镜像到远程cd to dockerfile directorysudo docker build -t orange5 ./sudo docker psdocker tag 1adec2c ...

  7. Python装饰器用法

    在Python中,装饰器一般用来修饰函数,实现公共功能,达到代码复用的目的.在函数定义前加上@xxxx,然后函数就注入了某些行为,很神奇!然而,这只是语法糖而已. 场景 假设,有一些工作函数,用来对数 ...

  8. 【OpenFOAM案例】01 elbow

    本案例演示利用OpenFOAM的icoFoam求解器计算弯曲管道中的混合流动问题. 1 拷贝tutorials文件 启动终端,且拷贝tutorials文件夹中的文件.利用命令: cp -r $FOAM ...

  9. 明天软软onsite

    现在在飞机上,还有1.5小时到达.买了网络包,速度不错.今年上半年第三次飞西雅图,过几天也许还有第四次... 今天群主FB加面系统设计非常顺利,祝他拿到大包裹,也希望拿到以后发大红包,这回我一定不能错 ...

  10. vscode打造最佳的markdown编辑器

    参考:https://www.jianshu.com/p/18876655b452 在macos下也设置成功: