[sicily]1636. show me the money

1636. show me the money

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Fakosh like playing the game "StarCraft".  However, he is not so good at this game that he can't beat the AI. For victory, he typed "show me the money" to cheat, and then he would get some money in the game. Now he can build more powerful cannons and make more strong soldiers with the money. But maybe the money is not enough, so he wants to know the amount of the money left.

Input

The first line of the input is an integer T, the number of test cases.

In each test case, the first line is the money M(1<=M<=1000) that Fakosh would get after he typed "show me the money", and N(1<=N<=5), the number of kinds of the cannons or soldiers he would like to make. Each of the next N lines will contain two integers Ai(1<=Ai<=100) and Bi(1<=Bi<=5). Ai is the price of the cannon or soldier, Bi is the number of the cannon or soldier of this kind he would like to make.

Output

For each test case, if the money is not enough, output "Not enough", or else output the amount of the money left, in one line.

Sample Input

3         //测试用例个数
10 2      //有10块钱,需要2种类型装备 
5 1	  //一个装备5块钱,要买1个
3 1
100 2
25 2	  // 一个装备25块钱,要买2个
50 1
8 1
3 3

Sample Output

2
0
Not enough

简单的算术题。就是问我们那谁玩游戏买装备够不够钱,够钱买完之后还剩多少。直接算呗。代码如下:

#include <iostream>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int m,n;
        cin>>m>>n;
        int cost = 0;
        for(int i=0; i<n; i++)
        {
            int a,b;
            cin>>a>>b;
            cost += a*b;
        }
        if(cost>m)
            cout<<"Not enough"<<endl;
        else
            cout<< m-cost<<endl;
    } 
    //system("pause");
    return 0;   
}                                 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值