# MARCH LUNCHTIME

Actually i am not getting a question of march lunchtime.
here i am providing the link of that question.
plz explain with example of 99 and 9 ,58 and 2.

Here you have to maximise the sum by swapping atmost one digit only so, the cases which can be made for 58 and 2 are :-
1.) 58 + 2 = 60 (if we don’t swap any digit)
2.) 28 + 5 = 33 (if we swap 5 and 2)
3.) 52 + 8 = 60 (if we swap 8 and 2)

as the maximum sum is 60 therefore,answer is 60

For 99 and 9 if swap any digit the answer will remain same i.e. sum=108

1 Like

The inputs can be of 4 types:

1. a = 1 digit no. b= 1 digit no.
2. a = 1 digit no. b = 2 digit no.
3. a = 2 digit no. b = 1 digit no.
4. a = 2 digit no. b = 2 digit no.

Now let’s look at these cases one by one.

Case I
Since swapping won’t make a difference, the answer will simple be `a+b`.

Case II
Let b = 10*x + y
Now you can swap `a` with either `x` or `y`. The following numbers result:

1. 10*x+ a, y (Sum = `10*x + a + y`)
2. 10*a + y, x (Sum = `10*a + y +x`)

Looking at 1 carefully, you will realize `a+b = 10*x+ a + y`. Hence we disregard this case.
Therefore, the answer to this case will be the maximum of `a+b` and `10*a + y +x`.

Case III
By symmetry to case II, you can conclude that the answer will be maxium of `a+b` and `10*b + y + x` where `y` and `x` are unit’s and ten’s digit of `a`.

Case IV
Let `a = 10*x + y` and `b = 10*p + q`.
Try to find the number of cases you can come after swapping. These are the cases you should arrive at:

1. 10x + p, 10y + q
2. 10q + y, 10p + x

Therefore, the answer to this case will be `a+b`, `10*x + p + 10*y + q` and `10*q + y + 10*p + x`.

okay @algo_master i got it but i wanna ask you a question as only 13 and 82 is explained in the question so how u got that x will not be swapped with p???        Are we actually supposed to do this much of case work for the easiest problem of the contest ?even just bruteforcing through all possible answers will pass for such small constraints😅

@algo_master i have tried the code but it is giving error the code was very similar to u but it is not recognising my function call . the following is my code

#include<bits/stdc++.h>
#define n 10
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int a,b;
cin>>a>>b;

``````    if(a<10&&b<10)//comparing with 10 basically means checking digit;
cout<<a+b<<endl;
else
if(a<10&&b>=10)
cout<<max(a+b,10*a+(b%10)+(b/10))<<endl;
else
if(a>=10&&b<10)
cout<<max(10*b+(b%10)+(b/10),a+b)<<endl;
else
if(a>=10&&b>=10)
``````

{
cout<<max(a+b,10*(b%10)+(a%10),10*(b/10)+(a/10),10*(a/10)+(b/10),10*(a%10)+b%n);
cout<<"\n";
}
}
}

hey @cubefreak777 @chef
i wanna ask you a question as only 13 and 82 is explained in the question so how u got that x will not be swapped with p???        Because it won’t change the overall sum

ohhh thanks a lot @cubefreak777 now i got it      but my code is not working can u check it ???plz…

Bro the code is not even compiling how can you expect it to get accepted

ya i got that damn mistake i was not writing the max function correctly

@cubefreak777
Bro it’s still not working although all test cases are satisfied
"
#include<bits/stdc++.h>
#define n 10
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int a,b;
cin>>a>>b;

``````    if(a<10&&b<10)//comparing with 10 basically means checking digit;
cout<<a+b<<endl;
else
if(a<10&&b>=10)
cout<<max(a+b,10*a+(b%10)+(b/10))<<endl;
else
if(a>=10&&b<10)
cout<<max(10*b+(b%10)+(b/10),a+b)<<endl;
else
if(a>=10&&b>=10)
``````

{
cout<<max({a+b,10*(b%10)+(a%10)+10*(b/10)+(a/10),10*(a/10)+(b%10)+10*(a%10)+(b%10)});
cout<<endl;
}
}
}
"

https://www.codechef.com/viewsolution/30875262

this is the link to my solution

https://www.codechef.com/viewsolution/30875262

``````4
@cubefreak777 it’s done thanks for supporting and helping      