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. 你真的会打 Log 吗

    前言 工程师在日常开发工作中,更多的编码都是基于现有系统来进行版本迭代.在软件生命周期中,工程维护的比重也往往过半.当我们维护的系统出现问题时,第一时间想到的是查看日志来判断问题原因,这时候日志记录如 ...

  2. MFC更换窗口图标

      https://blog.csdn.net/deep_kang/article/details/72722692: MFC更换图标,图像默认为MFC,主要步骤有三步. 第一步 找到一张图片(坑点: ...

  3. H5调用本地摄像头[转]

    http://www.cnblogs.com/GoodPingGe/p/4726126.html <!DOCTYPE html><html><head lang=&quo ...

  4. IOS开发中xib和StoryBoard的优缺点

    总所周知,苹果官方为IOS开发提供了3种制作UI方式,让我们能够快速开发漂亮APP界面,每一种方式都有他们各自的特点,谁也不能代替谁.但是国内开发人员为此时争得不可开交. 大家各说各有理,说都想说服谁 ...

  5. (原)Max Area of Island(即连通域标记)

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/10493114.html 1. 问题 Given a non-empty 2D array grid ...

  6. Python之关于工具包简介

    1.Pandas Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标准的 ...

  7. 关于python协程中aiorwlock 使用问题

    最近工作中多个项目都开始用asyncio aiohttp aiomysql aioredis ,其实也是更好的用python的协程,但是使用的过程中也是遇到了很多问题,最近遇到的就是 关于aiorwl ...

  8. eclipse中项目jdk1.8刷新下就变成1.5的解决办法

    https://blog.csdn.net/qq_32814555/article/details/82803017 ***************************************** ...

  9. ssh连接服务器失败解决记录

    故障:db2inst1用户无法通过ssh连接数据库服务器. 但是root用户可以连接,连接后su – db2inst1用户报错: su: cannot set user id: Resource te ...

  10. Vue父子组件双向数据绑定

    [本文出自天外归云的博客园] 简介 Vue版本:2.9.6 Element版本:2.4.8 问题描述:子组件对Element中el-select进行封装,父组件中把选中的值selected和所有选项o ...