CMED202 - Editorial

PROBLEM LINK:

Practice

DIFFICULTY:

CakeWalk

PREREQUISITES:

None at all image

PROBLEM:

Given the counts (M and N) of a number of entries by two keepers, what is the minimum and a maximum number of entries that could have happened, given that at least one of them is always awake.

QUICK EXPLANATION:

The minimum occurs when they count as many as possible entries together. So the minimum would be the maximum(M, N).
Maximum occurs when each entry was counted only by one Keeper. So the maximum would be the sum of counts of both i.e. M+N.

EXPLANATION:

M ∪ N is the total number of entries.
To maximise M ∪ N, make M ∩ N = 0, then M ∪ N = sizeof(M)+sizeof(N).

To minimize M ∪ N, make anyone set as a subset of others. Then the M ∪ N = maximum(sizeof(M),sizeof(N)).

Pseudo code:

a,b=input()  
print max(a,b),a+b  

SOLUTIONS:

Solution
#include<bits/stdc++.h>
using namespace std;

#define i64 long long
#define MAX 1000000

int main(){
int t,a,b;
scanf("%d",&t);

while(t--){
    scanf("%d %d",&a,&b);
    printf("%d %d\n",max(a,b),a+b);

}
return 0;
}