Problem Description
John never knew he had a grand-uncle, until he received the notary’s letter. He learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the only inheritor.

John did not need that much money for the moment. But he realized that it would be a good idea to store this capital in a safe place, and have it grow until he decided to retire. The bank convinced him that a certain kind of bond was interesting for him.

This kind of bond has a fixed value, and gives a fixed amount of yearly interest, payed to the owner at the end of each year. The bond has no fixed term. Bonds are available in different sizes. The larger ones usually give a better interest. Soon John realized that the optimal set of bonds to buy was not trivial to figure out. Moreover, after a few years his capital would have grown, and the schedule had to be re-evaluated.

Assume the following bonds are available:
Value Annual interest
4000 400
3000 250

With a capital of 10 000 one could buy two bonds of 4 000, giving a yearly interest of 800. Buying two bonds of 3 000, and one of 4 000 is a better idea, as it gives a yearly interest of 900. After two years the capital has grown to 11 800 , and it makes sense to sell a 3 000 one and buy a 4 000 one, so the annual interest grows to 1 050. This is where this story grows unlikely: the bank does not charge for buying and selling bonds. Next year the total sum is 12 850, which allows for three times 4 000, giving a yearly interest of 1 200.

Here is your problem: given an amount to begin with, a number of years, and a set of bonds with their values and interests, find out how big the amount may grow in the given period, using the best schedule for buying and selling bonds.

Input
The first line contains a single positive integer N which is the number of test cases. The test cases follow.

The first line of a test case contains two positive integers: the amount to start with (at most 1 000 000), and the number of years the capital may grow (at most 40).

The following line contains a single number: the number d (1 <= d <= 10) of available bonds.

The next d lines each contain the description of a bond. The description of a bond consists of two positive integers: the value of the bond, and the yearly interest for that bond. The value of a bond is always a multiple of \$1 000. The interest of a bond is never more than 10% of its value.

Output
For each test case, output – on a separate line – the capital at the end of the period, after an optimal schedule of buying and selling.

Sample Input
1
10000 4
2
4000 400
3000 250

Sample Output
14050

0

C语言：编写程序，使用命令行操作程序计算两个两位数的乘法运算

C语言实现分数的四则运算
C语言实现分数的四则运算 #include&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;stdio.h&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; int main() { int a,b,d,e,f,g,m,n; f=0,g=0; char op; sca
c语言实现加法器，高精度计算a + b

C语言程序设计---2：数据的存储与运算

C语言 乘法计算
#include #include /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int weizhishu1,weizhishu2,weizhishu3,weiz
C语言实现序列卷积

c语言用栈实现带括号运算的简单计算器
c语言用栈实现带括号的简单计算器 写的简单，栈部分实现比较粗略，可能有没考虑到的地方 目录 c语言用栈实现带括号的简单计算器 目录 1.栈的简单实现 2.中缀转换为后缀 3.后缀运算 整体步骤分为三步： 1.栈的简单实现 2.中缀转换为后缀 3.后缀运算 1.栈的简单实现 typedef struct stack{ int val...

c++代码 #include using namespace std; class complex//类置于开始部分 { private: double imag;//虚部实部 double real; public: complex add(complex x);//四则运算 complex sub(complex x); comp
c语言幂运算
e的x次方的一个代码，很简单具体的问题。希望对你有帮助

C语言实现卷积代码
C语言实现一维卷积代码（失败）待修改 #include&amp;lt;iostream&amp;gt; using namespace std; int main() { int i,j,k,n,m,a[n],b[m],c[n+m-1]; cout&amp;lt;&amp;lt;&quot;输入n:&quot;; cin&amp;gt;&amp;gt;n; cout&amp;lt;&amp;lt;endl; cout&amp;lt;&amp;lt;&quot;输入m:&quot;; cin&

C语言及程序设计初步——计算求和

C语言编写的加减乘除运算
C语言编写的加减乘除运算
[C语言]用C语言处理简单的计算题

C语言实现卷积算法

C语言实现多达50位数相乘的运算
/* * 文件名：multiply.c * 功能：实现支持50位数乘以50位数&amp;amp;lt;用bc命令验证结果&amp;amp;gt; * 编辑人：王廷云 * 编辑时间：2017-12-20 */ #include &amp;amp;lt;stdio.h&amp;amp;gt; #include &amp;amp;lt;string.h&amp;amp;gt; #define NR 50 void reserverString(char *

1 在浏览器中打开 www.joinquant.com2 编写策略代码点击顶部的“我的策略”，选择子菜单“我的策略”，在左侧输入python代码def initialize(context): #初始化 g.security = '600050.XSHG' # 股票名:中国联通 def handle_data(context, data): #

#include&amp;lt;stdio.h&amp;gt; int main(void) { int a[2],b[2],c[2],d[2];//存储实部肯虚部和结果 printf(&quot;请输入第一个复数的实部和虚部：\n&quot;); scanf(&quot;%d%d&quot;,&amp;amp;a,&amp;amp;b); printf(&quot;您输入的复数为%d+%di\n&quot;,a[0],b[0]); printf(&quot;请输入第二个复数...
C语言实验——计算表达式
C语言实验——计算表达式

【c语言写计算器】利用函数写一个计算器 包括菜单功能和加减乘除四个功能
/* 利用函数写一个计算器 包括菜单功能和加减乘除四个功能 作者：NBDR_YL */ #include&amp;lt;stdio.h&amp;gt; int mean(void); //声明菜单的函数 float add(float,float);//声明加法的函数 float sub(float,float);//声明减法函数 float mul(float,float);//声明乘法...

C语言（CED）编写一个程序，求两个字符之间的加减运算。