Hello, I couldn't really understand what this problem wanted exactly and it's just confusing as hell. I am not a fan of geometry and any of that crap so if someone can explain the problem statement and/or the maths behind the solution?
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 10^18. 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.
#include <bits/stdc++.h>
#define ll long long
usingnamespace std;
ll series(ll x){
return x*(x+1)/2;
}
int main() {
int m,b;
cin >> m >> b;
ll best = 0;
for(int y = b; y >=0; y--){
//y = -x/m + b
ll x = m*(b-y);
ll t = 0;
t+=(x+1)*series(y)+(y+1)*series(x);
best = max(best,t);
}
cout << best << endl;
}
Its not the math, its the bad English that messes it up.
It clearly states there is only 1 tree, so 1,5 is 6, (1+5).
"A tree" (1 tree).
"No trees in other points".
This is not true, however, so the first part of the text is misleading and incorrect.
The question is, what is the largest area rectangle (or point, or line) you can fit under a line that maximizes the sum of all X+Y inside it. And the wording is so bad the only way to see that is to look at your picture and then re-read the thing 50 times and then ignore the first 2 incorrect statements.
Funny, I understood the meaning fine. \forall x,y \in N_{+0} banana(x,y) = x+y
The problem was that the line equation was missing y = -x/m + b
The problem ask you to find the (x,y) that maximises \sum_{j=0}^{x} \sum_{k=0}^{y} j+k
which may be written as \sum_{j=0}^{x} \sum_{r=0}^{y} j + \sum_{r=0}^{x} \sum_{k=0}^{y} k
subject to the line restriction y \leq -x/m+b