Okabe and Banana Trees

Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.

Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + y bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.

Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.

Okabe is sure that the answer does not exceed 1018. You can trust him.

Input

The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 1000, 1 ≤ b ≤ 10000).

Output

Print the maximum number of bananas Okabe can get from the trees he cuts.

Example
Input
1 5
Output
30
Input
2 3
Output
25
Note

The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.

题意:给你一条直线,在第一象限且在直线下画一个矩形,每个点(x,y)的香蕉数为x+y,矩形内包括边界上的香蕉可采,问最大香蕉数。

分析:按y讨论,香蕉数可用y计算得到,首先计算出最右边界,然后用等差数列求和导出香蕉总数公式,若不这样计算,会超时。

#include<stdio.h>
typedef long long ll;
ll m,b;
ll x,y;
ll sum1(ll c)
{
    return (0+c)*(c+1)/2;
}
int main()
{
    ll i,j;
    ll su1,su2;
    ll best;
    while(scanf("%lld%lld",&m,&b)!=EOF)
    {
        best=-1;
        su1=0;
        su2=0;
        for(i=0;i<=m*b;i++)
        {
            y=b+(-i)/m;
            if(i%m!=0) //如果不能被整除则y要减-1。
                y=y-1;

            su1=(i+1)*sum1(y);
            su2=sum1(i)*(y+1);
            if(su1+su2>best)
                best=su1+su2;
        }
        printf("%lld\n",best);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值