forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF.cpp
More file actions
104 lines (92 loc) · 2.61 KB
/
F.cpp
File metadata and controls
104 lines (92 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((int)(a).size())
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define eps 1e-12
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos(0))
#define linf (1ll << 60)
#define y1 y32432
#define y2 y435346
#define maxn 2005
int test;
ll M = 1000000005;
ll x1, y1, x2, y2, a1, b1, a2, b2;
ll k;
void swapS(ll &x, ll &y){
ll temp = M - x;
x = M - y;
y = temp;
}
ll intersect(ll u1, ll u2, ll v1, ll v2){
return max(0ll, min(u2, v2) - max(u1, v1));
}
vector<pair<ll, ll> > cal(ll u1, ll u2, ll v1, ll v2){
ll d = u2 - u1;
ll T = 0;
if(u2 < v1){
T = (v1 - u2 - 1) / d + 1;
}
vector<pair<ll, ll> > res;
res.pb(mp(T, intersect(u1 + T * d, u2 + T * d, v1, v2)));
res.pb(mp(T + 1, intersect(u1 + (T + 1) * d, u2 + (T + 1) * d, v1, v2)));
return res;
}
void solve(){
cin >> x1 >> y1 >> x2 >> y2;
cin >> a1 >> b1 >> a2 >> b2;
cin >> k;
x2 += x1; y2 += y1; a2 += a1; b2 += b1;
if(x1 > a1){
swapS(x1, x2);
swapS(a1, a2);
}
if(y1 > b1){
swapS(y1, y2);
swapS(b1, b2);
}
// cout << x1 << " " << x2 << " " << y1 << " " << y2 << endl;
// cout << a1 << " " << a2 << " " << b1 << " " << b2 << endl;
// cout << "zzzz" << endl;
vector<pair<ll, ll> > V1 = cal(x1, x2, a1, a2);
vector<pair<ll, ll> > V2 = cal(y1, y2, b1, b2);
ll res = 0;
Rep(i, sz(V1)) Rep(j, sz(V2)){
ll A = V1[i].fi + V2[j].fi;
ll B = V1[i].se * V2[j].se;
// cout << V1[i].se << " " << V2[j].se << endl;
if(A <= k) res = max(res, B);
}
cout << res << endl;
}
int main(){
// freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> test;
For(itest, 1, test){
solve();
}
return 0;
}