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. jquery自带的进度条功能如何使用?

    弹出进度条:先做弹出的功能modal,再做进度条显示.在弹出的界面上增加进度条功能 $.ajax({ xhr: function() { var xhr = new window.XMLHttpReq ...

  2. Centos7中离线安装DockerCE最新版

    一.简述 离线在Centos7中部署DockerCE. 二.步骤 (1)在有外网的计算A上执行: 1.配置安装源存放路径 mkdir -p /root/docker-ce-local &&am ...

  3. Linux命令行烧录树莓派镜像至SD卡

    首先下载镜像压缩包 验证压缩包的未被串改 1 sha1sum 2013-09-25-wheezy-raspbian.zip 对此命令的输出结果和官网给出的SHA-1 Checksum进行比对,如果一致 ...

  4. 理解ThreadPoolExecutor线程池的corePoolSize、maximumPoolSize和poolSize

    我们知道,受限于硬件.内存和性能,我们不可能无限制的创建任意数量的线程,因为每一台机器允许的最大线程是一个有界值.也就是说ThreadPoolExecutor管理的线程数量是有界的.线程池就是用这些有 ...

  5. JQuery : 插件定义

    来源:http://www.cnblogs.com/xcj26/p/3345556.html 一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写("#"), ...

  6. Jexus 5.4.6 on CentOS 6.6

    Mono 通过脚本安装 https://github.com/cjy37/linux-asp.net-installScript 版本 3.10 MongoDB 也可通过以上脚本安装 默认端口 270 ...

  7. Unty中通过镜像优化HDRI全景图体积

    全景图即HDRI贴图,可以代替6面cubemap,传统3D软件运用较为广泛.一般反射探针,天空盒等都会用到. 但是体积过大是个问题,特别是移动端会对包体大小进行控制,虽说可以通过球面贴图替换掉部分环境 ...

  8. [svc]容器网络学习索引及网络监控

    整理的可能有些误失,抽时间在细细的分类完善下. 发现这篇对于网络从低到高层协议整理的还不错 每层都有一些有意思的话题 一些协议有一些设计上的弱点, 所以产生了种种的网络层安全问题 一般我们学一些 1, ...

  9. ios 适配iOS11&iPhoneX的一些坑

    前阵子项目开发忙成狗,就一直没做iOS11的适配,直到XcodeGM版发布后,我胸有成竹的在iPhoneX上跑起项目,整个人都凉透了...下面总结一下我遇到的坑,不是很全面,日后补充. 导航栏 导航栏 ...

  10. CentOS7安装Java还是无法使用javac

    centos7.4 安装java之后,还是无法使用javac命令.报错提示: [root@ip---- centos]# javac bash: javac: command not found 解决 ...