Problem Description

Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:

each cut should be straight (horizontal or vertical);
each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times.

Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.

Input

A single line contains three integers n, m, k (1 ≤ n, m ≤ 109; 1 ≤ k ≤ 2·109).

Output

Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.

Examples

Input

3 4 1

Output

6

Input

6 4 2

Output

8

Input

2 3 4

Output

-1

Note

In the first sample, Jzzhu can cut the chocolate following the picture below:

In the second sample the optimal division looks like this:

In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.

题意:输入 n,m,k,代表一个 n*m 的矩阵要切 k 次,问切完后最小的单元格的最大值

思路:

假设横向切了 x-1 次,纵向切了 y-1 次,那么横着就分为 x 份,纵着就分为 y 份

于是结果即为:res=(n/x)*(m/y),而题目所给范围为:1<=x<=n,1<=y<=m,(x-1)+(y-1)=k

显然:(n+m-2)<k 时无解,(n+m-2)=k 时值为 1

可以考虑先枚举 n/x 的值,那么对于固定的取值,可以选出最大的 x,使得此时 m/y 最大;然后再枚举  n/y 的值,那么对于固定的取值,可以选出最大的 y,使得此时 n/x 最大,最后取两者最大值即可

我们将 y=k+2-x 代入 res=(n/x)*(m/y) 中可得到分母是一个二元函数:-y^2+2*y+ky,那么要让原式最大,就要让分母最小,因此不需枚举 x、y 的值,直接令 x、y 分别最小即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-9
#define INF 0x3f3f3f3f
#define LL long long
const int MOD=1e9+7;
const int N=10+5;
const int dx[]= {-1,1,0,0};
const int dy[]= {0,0,-1,1};
using namespace std;
int main(){int n,m,k;cin>>n>>m>>k;LL res=0;if( (n-1)+(m-1)<k )//刀数多于切口数res=-1;else if( (n-1)+(m-1)==k )//刀数等于切口数res=1;else{LL x=min(n-1,k);//令x最小res=max( res, (n/(x+1))*(m/(k+1-x)) );LL y=min(m-1,k);//令y最小res=max( res, (m/(y+1))*(n/(k+1-y)) );}cout<<res<<endl;return 0;
}

Jzzhu and Chocolate(CF-449A)相关推荐

  1. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  2. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  3. D. Make a Power of Two(cf#739DIV3)

    D. Make a Power of Two 链接: link. 题意: 找出将数字转换为 2 的任意幂的最小移动次数. 题解: 先将2的xxx次幂的结果以字符串形式保存,输入字符串nnn后,因为存在 ...

  4. Web of Lies(CF 1548A)

    这是今天在打个人赛时碰见的一道题,是一道半图论半思维的题. Web of Lies 题目大意不难理解,在这里只需要注意一些细节.在加边时,只有当cnt[min]的值为1时答案才应该减1,而不是当cnt ...

  5. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  6. 【解题报告】博弈专场 (CF 2000~2200)前五题

    [解题报告]博弈专场 (CF 2000+)前五题 A:Fox and Card Game | CF388C 题意 思路 代码 B:Berzerk | CF786A 题意 思路 代码 C:Ithea P ...

  7. 软件设计师提纲+复习资料整理(上午题)

    文章目录 软件设计师考试大纲 上午题(选择题) 一.计算机组成原理 考点:CPU结构组成 考点:原码.反码.补码定点整数范围 考点:浮点数表示 考点:RISC和CISC计算机的区别 考点:奇校验与偶校 ...

  8. HDU 2282 Chocolate (最小费用最大流)

    HDU  2282 Chocolate (最小费用最大流) #include <iostream> #include <cstdio> #include <queue&g ...

  9. c性能大容量cket_5千左右预算,既轻薄(高颜值)又高性能的笔记本推荐(畅玩LOL、CF、DNF、流放之路、梦幻西游)...

    在目前笔记本制造技术中,轻薄和性能二者不可兼得,轻薄的本性能不高,高性能的太厚重, 这里推荐一些既轻薄,外观好看,同时又高性能的轻薄本. 很多轻薄本多为低压U+集成显卡,性能太弱,都不适合玩大型3D网 ...

最新文章

  1. 李宏毅机器学习笔记六——Gradient Descent
  2. python简易爬虫课程设计_python实现简单爬虫功能的示例
  3. 批处理常用命令及用法大全
  4. ElementUI 中日期选择器总结
  5. Flutter之Align
  6. 大公司的老板更专注人,小公司的老板更专注事
  7. 代码精进之路读后感(三)
  8. java 发卡平台支付_基于jsp的自动发卡平台-JavaEE实现自动发卡平台 - java项目源码...
  9. 用计算机配置打印机IP,如何修改打印机IP地址?
  10. Java-面试-逻辑题
  11. An Attention-based Graph Neural Network for Heterogeneous Structural Learning
  12. 何为“定向融资计划”?适合你投资吗?
  13. 云集宣布品牌升级,推出全新slogan“购物享受批发价”
  14. 攻防世界 —— Crypto新手练习区7题(不仅仅是Morse)题解
  15. [分享] 【强烈推荐】要速度更要方便!75款实用Chrome插件推荐
  16. pycharm远程连接服务器完整教程
  17. 绝对干货3000字,手把手带你用Python实现一个量化炒股策略,小白也能看得懂!...
  18. Go语言xorm框架
  19. SVN conflict的解决办法
  20. 如何在Ubuntu 18.04上使用Nginx与MySQL服务器一起部署ASP.NET Core应用程序

热门文章

  1. JavaEE实战班第三天
  2. 新书进展和我的决定。
  3. Java 14 发布了,再也不怕 NullPointerException 了!
  4. 资深架构专家聊小团队中微服务困境及分布式事务解决方案
  5. 蚂蚁集团涵畅:再启程,Service Mesh 前路虽长,尤可期许
  6. SpringMVC实现RESTful风格
  7. 【视频教程】JEECG 入门视频教程
  8. 深入掌握JMS(四):实战Queue
  9. VS 2017 C++查看变量
  10. “ == “运算符与equals()方法的区别