CodeForces - 821B Okabe and Banana Trees 解题
B. 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.
The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 1000, 1 ≤ b ≤ 10000).
Print the maximum number of bananas Okabe can get from the trees he cuts.
1 5
30
2 3
25
![](http://codeforces.com/predownloaded/10/69/10699292efb44f697451e187d3ee293627640630.png)
The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<algorithm> 6 #include<queue> 7 #include<vector> 8 #include<stack> 9 #include<map> 10 #include<set> 11 #include<cmath> 12 #include<cctype> 13 #include<ctime> 14 15 using namespace std; 16 17 int main() 18 { 19 long long m,b,x,num=0; 20 scanf("%lld%lld",&m,&b); 21 for(int i=0;i<=b;i++) 22 { 23 long long sum=0; 24 x=m*(b-i); 25 sum=(x*(x+1)/2)*(i+1)+(i*(i+1)/2)*(x+1); 26 if(sum>num) num=sum; 27 } 28 printf("%lld\n",num); 29 return 0; 30 }