#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define mkp make_pair
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base:: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t; cin >> t; while (t--)
{
int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
int gl, gb;
cin >> gl >> gb >> n;
int row[n + 2], col[n + 2];
row[0] = 1;
col[0] = 1;
row[n + 1] = gl;
col[n + 1] = gb;
for (int i = 1; i <= n; ++i)
{
int temp_row, temp_col;
cin >> temp_row >> temp_col;
row[i] = temp_row;
col[i] = temp_col;
}
sort(row, row + n + 2);
int temp = 1;
int diff_row = 1;
sort(col, col + n + 2);
for (auto x : row) {
if (x - temp > diff_row) {
diff_row = x - temp;
}
temp = x;
}
temp = 1;
int diff_col = 1;
for (auto x : col) {
if (x - temp > diff_col) {
diff_col = x - temp;
}
temp = x;
}
int area = (diff_row - 1) * (diff_col - 1);
if (area <= 0) {
cout << 0 << endl;
}
else {
cout << area << endl;
}
}
}
Code giving wrong ans
question
I made some minor changes in your code.
issue is that you considered the end points in the same way as mid points. means width at start and end will be +1 as compared to mid.
check modified code here: https://ide.codingblocks.com/s/209787
thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
1 Like