-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathB.cpp
62 lines (48 loc) · 798 Bytes
/
B.cpp
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
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
void solve(){
// Solve here
ll a, b, x, y, n;
cin>>a>>b>>x>>y>>n;
// cout<<(a-x)+(b-y)<<endl;
if((a-x)+(b-y) < n) {
cout<<min(min((a*y), (b*x)), (x*y))<<endl;
return;
}
ll p = (a-n);
ll q = (b-n);
ll ans1, ans2;
if(p<x) {
ll temp = x-p;
ll temp1 = b-temp;
ans1 = temp1*x;
} else {
ans1 = p*b;
}
if(q<y) {
ll temp = y-q;
ll temp1 = a-temp;
ans2 = temp1*y;
} else {
ans2 = q*a;
}
cout<<min(ans1, ans2)<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}