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.
The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
1
1
25
4
Illustration to the second sample:

题意:能堆几层,一层(1-n)的和;
思路:水;
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7; int a[N]; int main() { int x,sum=0; for(int i=1;i<=1000;i++) { sum+=i; a[i]=sum+a[i-1]; } scanf("%d",&x); printf("%d ",upper_bound(a+1,a+1001,x)-(a+1)); return 0; }
题意:n个灯,L长度的路,求灯最少的照射长度,使得灯把这路全部照亮;
思路:拍个序,前后端点特判;
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7; double a[N]; int main() { int n,l; scanf("%d%d",&n,&l); for(int i=1;i<=n;i++) scanf("%lf",&a[i]); sort(a+1,a+1+n); double ans=0; for(int i=2;i<=n;i++) ans=max(ans,(a[i]-a[i-1])/2); ans=max(a[1],max(ans,l-a[n])); printf("%f ",ans); return 0; }
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.
The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
1
1
25
4
Illustration to the second sample:
