Time spent here:

Monday, 1 February 2016

ANN AND JIMMY-HOUR RANK 5

Jimmy puts Ann's birthday present in a cuboid box. The dimensions of its edges are positive integers and the sum of its lengthwidth, and height is N.
What is the maximum volume Ann's present box can have?
                                                length+width+height=N
Input Format
A single integer, N (the sum of the box's lengthwidth, and height).
Constraint
3N103
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