Jimmy puts Ann's birthday present in a cuboid box. The dimensions of its edges are positive integers and the sum of its length , width , and height is N .
What is the maximum volume Ann's present box can have?
Input Format
A single integer, N (the sum of the box's length , width , and height ).
Constraint
3≤N≤103
Output Format
Print the maximum possible volume of the box.
SOLUTION:
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,ans=0;
cin>>N;
for (int i=1;i<=N;i++)
for (int j=1;j<=N && i+j<=N;j++)
ans=max(ans,i*j*(N-i-j));
cout<<ans<<"\n";
return 0;
}
No comments:
Post a Comment