Problem Statement
Limak is a little polar bear. Today he found two things in the snow: a bucket of blue paint and a white rectangular grid with W times H square cells.
Limak is going to paint some (possibly even all) cells blue. He wants to do it in such a way that the blue cells will form a completely filled blue rectangle. He has enough paint for M cells. What is the largest possible area of a blue rectangle he can paint?
Definition
- Class:
- BearPaints
- Method:
- maxArea
- Parameters:
- int, int, long
- Returns:
- long
- Method signature:
- long maxArea(int W, int H, long M)
- (be sure your method is public)
Constraints
- W and H will be between 1 and 10^6, inclusive.
- M will be between 1 and 10^12, inclusive.
Examples
3
5
14
Returns: 12
Limak has a grid that is W = 3 cells wide and H = 5 cells tall. He doesn't have enough paint to color all 15 cells. He also cannot color just 14 or 13 cells in a way that would produce a blue rectangle. The best he can do is to color four consecutive rows blue. This will produce a blue rectangle. Its area is 12 squares.
4
4
10
Returns: 9
Here the best solution is to paint a rectangle of size 3 times 3 blue. (A square is a valid rectangle.)
1000000
12345
1000000000000
Returns: 12345000000
Limak has more than enough paint to make whole grid blue.
1000000
1000000
720000000007
Returns: 720000000000
Limak's grid is a square with side 10^6. Limak can paint a rectangle of size 800,000 times 900,000.
1000000
1000000
999999999999
Returns: 999999000000
1
1
1
Returns: 1
fake
1
1
1
Returns: 1
fake
10
4
39
Returns: 36
5
200
969
Returns: 965
42
42
637
Returns: 630
50
40
1999
Returns: 1960
100
80
1999
Returns: 1998
1000
1000
539513
Returns: 539513
1234
5678
6266105
Returns: 6266086
10000
11000
17156467
Returns: 17156466
60123
40444
1718712911
Returns: 1718712910
100000
100000
5743503921
Returns: 5743503921
222222
333333
43915046249
Returns: 43915046245
333333
333333
18663519622
Returns: 18663519613
500000
500000
181504473609
Returns: 181504473598
500000
333333
15535507965
Returns: 15535507965
900000
1000000
104953809401
Returns: 104953809400
1000000
1000000
946750292918
Returns: 946750292895
1000000
1000000
918837635615
Returns: 918837635606
1000000
1000000
999880002374
Returns: 999880002304
1000000
1000000
88137170681
Returns: 88137170681
1000000
1000000
995083890056
Returns: 995083889634
1000000
1000000
999890002999
Returns: 999890002989
1000000
1000000
535383495209
Returns: 535383495207
1000000
1000000
999718003751
Returns: 999718003497
1000000
1000000
999901001637
Returns: 999901001580
1000000
1000000
687718841125
Returns: 687718841121
1000000
1000000
999912001310
Returns: 999912001260
1000000
1000000
999867003365
Returns: 999867003300
1000000
1000000
813873836291
Returns: 813873836288
1000000
1000000
999848004550
Returns: 999848004480
1000000
1000000
999976000127
Returns: 999976000119
1000000
1000000
666000272771
Returns: 666000272768
1000000
1000000
999984000059
Returns: 999984000055
1000000
1000000
999839006479
Returns: 999839006478
1000000
1000000
599281916516
Returns: 599281916516
1000000
1000000
999955000265
Returns: 999955000234
1000000
1000000
999967000241
Returns: 999967000230
1000000
1000000
296746755641
Returns: 296746755633
1000000
1000000
999979000019
Returns: 999979000000
1000000
1000000
999894002759
Returns: 999894002745
919951
938799
434438968179
Returns: 434438968174
854655
881521
752219640699
Returns: 752219640576
999836
913434
913200891094
Returns: 913200878800
939712
825223
403562436283
Returns: 403562436280
833219
854736
711580741944
Returns: 711580740948
924438
893788
826144937079
Returns: 826144931891
985181
844389
464714217359
Returns: 464714217352
899881
884588
795766922387
Returns: 795766914738
945146
886920
838158167395
Returns: 838158156745
840760
981587
516927949742
Returns: 516927949739
974827
820344
799597543517
Returns: 799597539405
889669
862740
767523296249
Returns: 767523269324
804784
874849
308149391204
Returns: 308149391204
899273
984644
885409864660
Returns: 885409859556
864672
952231
823271757989
Returns: 823271757120
807132
802162
271635585517
Returns: 271635585516
929579
979863
910833587079
Returns: 910833536805
950514
823809
782951243899
Returns: 782951242240
863621
955298
212637057188
Returns: 212637057182
974378
863991
841834906175
Returns: 841834887048
858201
824681
707648289708
Returns: 707648276398
969057
962062
682267479195
Returns: 682267479192
976848
962657
940369565135
Returns: 940368602479
942463
982018
925468500926
Returns: 925468493470
999999
857425
768971740310
Returns: 768971740302
999999
999999
999998000000
Returns: 999997000002
100000
100000
1000000000
Returns: 1000000000
999999
999999
999986000014
Returns: 999986000013
1000000
1000000
1000000000000
Returns: 1000000000000
1000000
1000000
10000000000
Returns: 10000000000
12345
1000000
1000000000000
Returns: 12345000000
99999
99999
999999999
Returns: 999999990
1000000
1000000
10000
Returns: 10000
100000
100000
1
Returns: 1
1000000
1000000
1000007
Returns: 1000007
3
3
10
Returns: 9
1000000
1000000
3
Returns: 3
4
3
8
Returns: 8
1
10
7
Returns: 7
4
4
16
Returns: 16
10
10
14
Returns: 14
99678
93467
1999444332
Returns: 1999444330
7
7
10
Returns: 10
1
1000000
1
Returns: 1
4
5
10
Returns: 10
4
6
15
Returns: 15
1000000
1000000
1
Returns: 1
30
30
97
Returns: 96
100000
100000
10000000
Returns: 10000000
7
4
10
Returns: 10
11
4
11
Returns: 11
121212
545445
12131346436
Returns: 12131346436
1
1
2
Returns: 1
2
4
3
Returns: 3
1000000
1000000
999999999998
Returns: 999999000000
1
1
5
Returns: 1
6
3
18
Returns: 18
3
5
2
Returns: 2
1000000
999999
10000000000
Returns: 10000000000
3
4
1
Returns: 1
5
10
4
Returns: 4
1
1000000
9
Returns: 9
3
3
4
Returns: 4
1000000
1000000
10
Returns: 10
5
5
2
Returns: 2
100
100
50
Returns: 50
7
10
42
Returns: 42
1000000
1000000
1000
Returns: 1000
1000000
1000000
1000000
Returns: 1000000
30
10
24
Returns: 24
5
7
22
Returns: 21
6
5
24
Returns: 24
3
4
10
Returns: 9
121212
545445
22000000000
Returns: 22000000000
3
4
8
Returns: 8
5
4
6
Returns: 6
100000
3
34
Returns: 34
1
1
10
Returns: 1
2
1
5
Returns: 2
5
3
10
Returns: 10
7
4
21
Returns: 21
5
2
5
Returns: 5
5
10
50
Returns: 50
1000000
1000000
851127775848
Returns: 851127775846
3
5
8
Returns: 8
1
1
1000000000
Returns: 1
10
10
73
Returns: 72