Untitled
unknown
plain_text
9 months ago
1.9 kB
11
Indexable
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <numeric>
#include <cstdio>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define In(type, name) \
type name; \
cin >> name;
#define For(var, constant, init) for(int var = init; var < constant; var++)
#define Sp << ' ' <<
#define End << '\n'
#define PI 3.141592653589793238462643383279502884L
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define ld long double
#define MOD 1000000007
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
In(int, t);
while(t--) {
ll n, m, x, y, k;
ll answer = 0;
cin >> n >> m >> x >> y >> k;
x--; y--;
// The boundaries of the rectangle
ll l = 0, r = m - 1, u = 0, d = n - 1;
// Greadily choose the side with the maximum area
For(i,min((ll)4,k),0) {
// Get area of each side
ll left = (y - l) * (d - u + 1);
ll right = (r - y) * (d - u + 1);
ll up = (x - u) * (r - l + 1);
ll down = (d - x) * (r - l + 1);
// Get the maximum area
ll mx = max({left, right, up, down, (ll)0});
answer += mx;
// Adjust the boundaries accordingly
/*
if two sides have the same area as the maximum area, would that be a problem?
*/
if (mx == left)
l = y;
else if (mx == right)
r = y;
else if (mx == up)
u = x;
else if (mx == down)
d = x;
}
cout << answer End;
}
}Editor is loading...
Leave a Comment