Apocalypse Revisited - EndGAME CodeChef Beginner Level Question

If you have seen the earlier post , this is just a modified version of that question .

Here is a link to the PROBLEM

So , this soluion is even simpler , as now the virus can even spread diagonally , the virus will start covering squares until the boundary is reached .
Hence our answer would be just the maximum of the blocks the virus has to cover to reach the boundary in all the 4 directions.

Do look at the below C++ code for clarity :-

Code :-

#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--)
    {
        long int r,c;
        cin>>r>>c;
        r--;c--;
        long int x,y;
        cin>>x>>y;
        long int max=0;
        if(x>max)
        {
            max=x;
        }
        if(y>max)
        {
            max=y;
        }
        if(r-x>max)
        {
            max=r-x;
        }
        if(c-y>max)
        {
            max=c-y;
        }
        cout<<max<<endl;
    }
// your code goes here
return 0;
}



Do leave your doubts and requests in the comments section .
Do follow and subscribe our blog for more competitive programming questions and solutions .

Comments

Popular Posts