Water Buying
1 second
256 megabytes
standard input
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.
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.
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的更多相关文章
- 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> ...
- [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 ...
- [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 ...
- [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 ...
- [LeetCode] Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- 【leetcode】Container With Most Water
题目描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...
- [LintCode] Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
随机推荐
- c++中transform()函数和find()函数的使用方法。
1.transform函数的使用 transform在指定的范围内应用于给定的操作,并将结果存储在指定的另一个范围内.transform函数包含在<algorithm>头文件中. 以下是s ...
- Go 语言学习笔记
1. go没有static关键字 面向对象编程中,尽量对函数进行封装,对于没有函数变量的对象,使用static关键字尤其方便. go中没有static关键字,必须每次new一个出来. type Han ...
- bootstrap-实现loading效果
可以使用bootstrap的模态框(modal.js),使用它我们可以做出loading效果. html <!-- loading --> <div class="moda ...
- CentOs7 HP找回root密码
linuxman本人尝试了两种方式修改密码,只有一种成功.现展示如下第一种:成功1. 在启动界面选择 centos linux, with linux***.x86_642. 按 e 键进入编辑模式 ...
- virltualbox 升级之后 苹果虚拟机报The installed support driver doesn't match the version of the user解决方案
1.反安装virtualbox后,不要重启 2.删除virtualbox的安装目录 3.进入%userprofile% 目录 (比如: C:\users\me) 删除 .VirtualBox Virt ...
- 转发:entos7修改文件夹权限和用户名用户组
Linux系统下经常遇到文件或者文件夹的权限问题,或者是因为文件夹所属的用户问题而没有访问的权限.根据我自己遇到的情况,对这类问题做一个小结.在命令行使用命令“ll”或者“ls -a”,可以查看文件或 ...
- 3分钟搞明白信用评分卡模型&模型验证
信用评分卡模型在国外是一种成熟的预测方法,尤其在信用风险评估以及金融风险控制领域更是得到了比较广泛的使用,其原理是将模型变量WOE编码方式离散化之后运用logistic回归模型进行的一种二分类变量的广 ...
- fastcgi php-cgi与php-fpm区别和之间的关系
关于FastCGI.php-cgi.php-fpm的区别是什么,各自有什么用途,以及相互间的关系是什么,查阅相关资料,可谓是众说纷纭,莫衷一是: 说法一:fastcgi是一个协议,php-fpm实现了 ...
- Win10正式企业版激活方法
Win10正式企业版激活方法 在正式开始激活Win10正式企业版系统之前,我们需要先查看一下当前Win10正式企业版系统的激活状态: 右击桌面左下角的“Windows”按钮,从弹出的右键菜单中选择“控 ...
- scrapy框架Selector提取数据
从页面中提取数据的核心技术是HTTP文本解析,在python中常用的模块处理: BeautifulSoup 非常流行的解析库,API简单,但解析的速度慢. lxml 是一套使用c语言编写的xml解析 ...