codeforces - 821B-(在函数中求包含的点值想加的最大值)

题面:

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.

Examples

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.

这个题世道简单题哦,要知道最大的值一定是整数点的,y一定是比x小的,所以只要暴力枚举y这条边就好了。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int maxn=1e7+10;
const int INF=0x3f3f3f3f;
const double EPS = 1e-10;
inline int read(){
    int ret=0,f=0;char ch=getchar();
    while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
    while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
    return f?-ret:ret;
}
ll m,b;
int main()
{
	ios::sync_with_stdio(false);
	cin>>m>>b;
	ll y=b;
	ll ans =0;
	for(ll i=y;i>=0;i--){
		ll x = (b-i)*m;
		ans = max(ans,(1+i)*i/2*(x+1)+(1+x)*x/2*(i+1));
		//cout<<ans<<endl;
}
	cout<<ans<<endl;
 	return 0;
}

很nice

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值