[Codeforces492A] Vanya and Cubes

描述 Description

Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + … + (i - 1) + i cubes.

Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.

输入格式 InputFormat

The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.

输出格式 OutputFormat

Print the maximum possible height of the pyramid in the single line.

样例输入 SampleInput

4115

样例输出 SampleOutput

28


Codeforces 492A


代码 Code

水。

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int i,j,t,n,m,l,r,k,z,y,x;
int ans,sum;
int main()
{
    scanf("%d",&n);
    ans=sum=0;
    for (i=1;sum<=n;i++)
    {
        t=t+i;
        if (sum+t<=n) ans++;
        else break;
        sum+=t;
    }
    printf("%d\n",ans);
    return 0;
}