1636. show me the money
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
5 1
3 1
100 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,result=0;
cin>>m>>n;
while(n--)
{
int a,b;
cin>>a>>b;
result+=a*b;
}
if(result>m) cout<<"Not enough"<<endl;
else cout<<m-result<<endl;
}
return 0;
}