Can someon tell me why this code is giving wrong output for this code(SPOJ)

Below code does is showing wrong output for sample test cases.

Problem Link:

Code:

#include "bits/stdc++.h"
#define ll long long int
using namespace std;
int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        ll width, height, n;
        cin >> width >> height >> n;

        if (n == 0)
        {
            cout << height * width << endl;
            continue;
        }
 
        vector<ll> coordinatesX(n);
        vector<ll> coordinatesY(n);
        for (ll i = 0; i < n; i++)
        {
            cin >> coordinatesX[i];
            cin >> coordinatesY[i];
        }
        coordinatesX.push_back(width + 1);
        coordinatesY.push_back(height + 1);
        ll maxwidth = coordinatesX[0] - 1;
        ll maxheight = coordinatesY[0] - 1;
        sort(coordinatesX.begin(), coordinatesX.end());
        sort(coordinatesY.begin(), coordinatesY.end());
        for (ll i = 1; i <= n; i++)
        {
            maxwidth = max(coordinatesX[i] - coordinatesX[i - 1] - 1, maxwidth);
            maxheight = max(coordinatesY[i] - coordinatesY[i - 1] - 1, maxheight);
        }

        cout << maxwidth * maxheight << endl;
    }
    return 0;
}

You have to assign after sorting, so re-write it as:

sort(coordinatesX.begin(), coordinatesX.end());
sort(coordinatesY.begin(), coordinatesY.end());
ll maxwidth = coordinatesX[0] - 1;
ll maxheight = coordinatesY[0] - 1;

ok thanks :grinning: :grinning: