附一份CF给出的题解。。。。。
We assume that n ≤ m (if n > m, we can simply swap n and m).
If we finally cut the chocolate into x rows and y columns (1 ≤ x ≤ n, 1 ≤ y ≤ m, x + y = k + 2), we should maximize the narrowest row and maximize the narrowest column, so the answer will be floor(n / x) * floor(m / y).
There are two algorithms to find the optimal (x, y).
-
Notice that if x * y is smaller, the answer usually will be better. Then we can find that if k < n, the optimal (x, y) can only be {x = 1, y = k + 1} or {x = k + 1, y = 1}. If n ≤ k < m, the optimal (x, y) can only be {x = 1, y = k + 1}. If m ≤ k ≤ n + m - 2, the optimal (x, y) can only be {x = k + 2 - m, y = m}, because let t = m - n, n / (k + 2 - m) ≥ (n + t) / (k + 2 - m + t) ≥ 1.
-
floor(n / x) has at most values, so we can enum it and choose the maximum x for each value.
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 20005
#define eps 1e-10
#define mod 1000000009
#define INF 99999999
#define lowbit(x) (x&(-x))
//#define lson o<<1, L, mid
//#define rson o<<1 | 1, mid+1, R
typedef long long LL;
//typedef int LL;
using namespace std;
int main(void)
{
LL n, m, k;
scanf("%I64d%I64d%I64d", &n, &m, &k);
if(n > m) swap(n, m);
if(k > n+m-2) {
printf("-1\n");
return 0;
}
if(k < n) printf("%I64d\n", max(n/(k+1)*m, m/(k+1)*n));
else if(k < m) printf("%I64d\n", m/(k+1)*n);
else printf("%I64d\n", n/(k-m+2));
return 0;
}