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. 让Linux系统开机速度更快的方法

    进行 Linux 内核与固件开发的时候,往往需要多次的重启,会浪费大把的时间. 在所有我拥有或使用过的电脑中,启动最快的那台是 20 世纪 80 年代的电脑.在你把手从电源键移到键盘上的时候,BASI ...

  2. 主流CTR预估模型的演化及对比

    https://zhuanlan.zhihu.com/p/35465875 学习和预测用户的反馈对于个性化推荐.信息检索和在线广告等领域都有着极其重要的作用.在这些领域,用户的反馈行为包括点击.收藏. ...

  3. grid - 网格轨道对齐方式

    网格轨道对齐可以相对于网格容器行和列轴. align-content指定网格轨道沿着行轴对齐方式:justify-content指定网格轨道沿着列轴对齐方式.它们支持下面属性: normal star ...

  4. Java WebSocket实现网络聊天室(群聊+私聊)

    1.简单说明 在网上看到一份比较nice的基于webSocket网页聊天项目,准备看看学习学习,如是有了这篇文章!原博主博客:http://blog.csdn.net/Amayadream/artic ...

  5. 人人网框架导入uidGenerator的ID生成方式

    人人网框架导入uidGenerator的ID生成方式 2019-03-11 LIUREN    SpringBoot2.0  uidGenerator  SpringBoot2.0  uidGener ...

  6. [oracle] Oracle存储过程里操作BLOB的字节数据的办法,例如写入32位整数

    作者: zyl910 一.缘由 BLOB是指二进制大对象,也就是英文Binary Large Object的缩写. 在很多时候,我们是通过其他编程语言(如Java)访问BLOB的字节数据,进行字节级的 ...

  7. “5W1H”带你来学习JavaScript

    上次的设计模式讲课,从中学习到了非常多.不仅是技术上,更重要的是怎样来学习.我们学习的技术.科技的更新速度超过我们的想象,对于我们这个有生命年限的个体,怎样可以在有生之年可以让自己立足于科技的不败浪潮 ...

  8. 19.翻译系列:EF 6中定义自定义的约定【EF 6 Code-First约定】

    原文链接:https://www.entityframeworktutorial.net/entityframework6/custom-conventions-codefirst.aspx EF 6 ...

  9. GridView不执行RowCommand事件

    web.config里把viewstate禁用了.如果是的话在页面里单独开起来就好了. <%@ Page Title="" Language="C#" M ...

  10. Android 源码学习

    工具篇:如何使用 Visual Studio Code 阅读 Android 源码:https://jekton.github.io/2018/05/11/how-to-read-android-so ...