Algorithm
problem link : https://www.codechef.com/problems/TAXSAVING!
Problem
In Chefland, everyone who earns strictly more than rupees per year, has to pay a tax to Chef. Chef has allowed a special scheme where you can invest any amount of money and claim exemption for it.
You have earned rupees this year. Find the minimum amount of money you have to invest so that you don't have to pay taxes this year.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of a single line of input consisting of two space separated integers and denoting the amount you earned and the amount above which you will have to pay taxes.
Output Format
For each test case, output a single integer, denoting the minimum amount you need to invest.
Constraints
Sample 1:
4 4 2 8 7 5 1 2 1
2 1 4 1
Explanation:
Test case : The amount above which you will have to pay taxes is . Since you earn rupees, you need to invest at least rupees. After investing rupees, you will remain with an effective income rupees which will not be taxed.
Test case : The amount above which you will have to pay taxes is . Since you earn rupees, you need to invest at least rupees.
Test case : The amount above which you will have to pay taxes is . Since you earn rupees, you need to invest at least rupees.
Test case : The amount above which you will have to pay taxes is . Since you earn rupees, you need to invest at least rupees.
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include<stdio.h>
int main()
{
int t, x, y;
scanf("%d", &t);
while(t--)
{
scanf("%d %d", &x, &y);
printf("%d\n", x-y);
}
}
Copy The Code &
Try With Live Editor
Input
4 2
8 7
5 1
2 1
Output
1
4
1
Demonstration
CodeCherf solution TAXGIVIN - Saving Taxes CodeCherf solution in C, C++