B. Minimum Product
You are given four integers a a a, b b b, x x x and y y y. Initially, a ≥ x a \ge x a≥x and b ≥ y b \ge y b≥y. You can do the following operation no more than n n n times:
- Choose either a a a or b b b and decrease it by one. However, as a result of this operation, value of a a a cannot become less than x x x, and value of b b b cannot become less than y y y.
Your task is to find the minimum possible product of a a a and b b b ( a ⋅ b a \cdot b a⋅b) you can achieve by applying the given operation no more than n n n times.
You have to answer t t t independent test cases.
Input
The first line of the input contains one integer t t t ( 1 ≤ t ≤ 2 ⋅ 1 0 4 1 \le t \le 2 \cdot 10^4 1≤t≤2⋅104) — the number of test cases. Then t t t test cases follow.
The only line of the test case contains five integers a a a, b b b, x x x, y y y and n n n ( 1 ≤ a , b , x , y , n ≤ 1 0 9 1 \le a, b, x, y, n \le 10^9 1≤a,b,x,y,n≤109). Additional constraint on the input: a ≥ x a \ge x a≥x and b ≥ y b \ge y b≥y always holds.
Output
For each test case, print one integer: the minimum possible product of a a a and b b b ( a ⋅ b a \cdot b a⋅b) you can achieve by applying the given operation no more than n n n times.
Example
input
7
10 10 8 5 3
12 8 8 7 2
12343 43 4543 39 123212
1000000000 1000000000 1 1 1
1000000000 1000000000 1 1 1000000000
10 11 2 1 5
10 11 9 1 10
output
70
77
177177
999999999000000000
999999999
55
10
Note
In the first test case of the example, you need to decrease b b b three times and obtain 10 ⋅ 7 = 70 10 \cdot 7 = 70 10⋅7=70.
In the second test case of the example, you need to decrease a a a one time, b b b one time and obtain 11 ⋅ 7 = 77 11 \cdot 7 = 77 11⋅7=77.
In the sixth test case of the example, you need to decrease a a a five times and obtain 5 ⋅ 11 = 55 5 \cdot 11 = 55 5⋅11=55.
In the seventh test case of the example, you need to decrease b b b ten times and obtain 10 ⋅ 1 = 10 10 \cdot 1 = 10 10⋅1=10.
题意
题目给出 a , b , x , y , n a,b,x,y,n a,b,x,y,n 其中n代表至多有 n n n次对 a , b a,b a,b减去一的操作
同时我们需要保证 a > = x , b > = y a >= x,b >= y a>=x,b>=y,求 a ∗ b a * b a∗b的最小值
分析
在此之前给出错误示范,哎!写的时候把这两数乘积的性质忘了。。。
本题给出N次操作,如果 a , b a,b a,b将n次操作全部用完后,得到的 a + b a + b a+b的和一定相同
同时我们还兼具着两数乘积最小,那么这两个数差值更大的性质
解决方法为分别对 a , b a,b a,b进行单独操作,如果n次操作没有用完去用没有达到临界点的一边,最终在两者中取最小值
如上方法涵盖了
a
=
=
b
,
a
>
b
,
a
<
b
a == b,a > b,a < b
a==b,a>b,a<b的情况,同时解决了10 11 9 1 10
这一组数据,是在是妙啊!!!
注意:不开long long见祖宗
A C C o d e AC\ Code AC Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#define str string
#define pb push_back
#define all(x) begin(x),end(x)
const int N = 1e6 + 10;
ll Calc(int a,int b,int x,int y,int n) {
ll ans = 1;
if(a - x >= n) {a -= n; n = 0;}
else {n -= (a - x); a = x;}
if(b - y >= n) {b -= n; n = 0;}
else {n -= (b - y); b = y;}
ans = 1ll * a * b;
return ans;
}
inline void solve() {
ll a,b,x,y,n; cin >> a >> b >> x >> y >> n;
cout << min(Calc(a,b,x,y,n),Calc(b,a,y,x,n)) << endl;
}
int main(){
// freopen("input.txt","r",stdin);
int t; cin >> t;
while(t--) solve();
// solve();
return 0;
}