My issue
My code
#include <iostream>
using namespace std;
int main() {
int T;
cin>>T;
for(int i=0;i<T;i++){
return 0;
}
Problem Link: CodeChef: Practical coding for everyone
#include <iostream>
using namespace std;
int main() {
int T;
cin>>T;
for(int i=0;i<T;i++){
return 0;
}
Problem Link: CodeChef: Practical coding for everyone
In the given problem statement, we have been given sum of T1 and T2, along with their maximum possible value.
As it is guaranteed that a solution exists, we have following possible cases;
CASE1: [ (T1 + T2)= (2*N) ], both dishes having maximum values.
In this case, the max difference can only be zero, as both dishes will have maximum tastiness value.
CASE2: [ (T1 + T2) <= N ], In this case, the as the sum is less than or equals to the maximum tastiness value, the difference will be the sum value itself since we can assign the other dish value to zero.
CASE3: [ (T1 + T2) > N ] and [ (T1+T2) < (2*N) ], in this case, one T would have to had max value and the other would be the difference between sum and max value.
The final answer will be the difference between max value and other value.
Here is my code for reference.
Although the following code is in C, the logic should remain the same.
#include <stdio.h>
int main(void)
{
int t,n,s;
scanf("%d",&t);
while(t--)
{
int c=0;
scanf("%d%d",&n,&s);
if((s>n)&&(s<(2*n)))
{
c=s-n;
printf("%d\n",(n-c));
}
else if(s==(2*n)) printf("0\n");
else if(s<=n) printf("%d\n",s);
}
return 0;
}
include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
for (int i=0;i<t;i++)
{
int a,b;
cin>>a>>b;
if(b<=a)
{
cout<<b<<endl;
}
else
{
cout<<a*2-b<<endl;
}
}
}