A. Vanya and Cubes
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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

Output

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

Examples
input
1
output
1
input
25
output
4
Note

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+,M=4e6+,inf=1e9+,mod=1e9+;
int a[N];
int main()
{
int x,sum=;
for(int i=;i<=;i++)
{
sum+=i;
a[i]=sum+a[i-];
}
scanf("%d",&x);
printf("%d\n",upper_bound(a+,a+,x)-(a+));
return ;
}
B. Vanya and Lanterns
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns.

Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?

Input

The first line contains two integers nl (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.

The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.

Output

Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.

Examples
input
7 15
15 5 3 7 9 14 0
output
2.5000000000
input
2 5
2 5
output
2.0000000000
Note

Consider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment[3, 5]. Thus, the whole street will be lit.

题意:n个灯,L长度的路,求灯最少的照射长度,使得灯把这路全部照亮;

思路:拍个序,前后端点特判;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
double a[N];
int main()
{
int n,l;
scanf("%d%d",&n,&l);
for(int i=;i<=n;i++)
scanf("%lf",&a[i]);
sort(a+,a++n);
double ans=;
for(int i=;i<=n;i++)
ans=max(ans,(a[i]-a[i-])/);
ans=max(a[],max(ans,l-a[n]));
printf("%f\n",ans);
return ;
}
C. Vanya and Exams
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi essays. He can raise the exam grade multiple times.

What is the minimum number of essays that Vanya needs to write to get scholarship?

Input

The first line contains three integers nravg (1 ≤ n ≤ 105, 1 ≤ r ≤ 109, 1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.

Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r, 1 ≤ bi ≤ 106).

Output

In the first line print the minimum number of essays.

Examples
input
5 5 4
5 2
4 7
3 1
3 2
2 5
output
4
input
2 5 4
5 2
5 2
output
0
Note

In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.

In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
struct grade
{
ll a,b;
bool operator <(const grade &a)const
{
return b<a.b;
}
}a[N];
int main()
{
ll n,r,ave;
scanf("%lld%lld%lld",&n,&r,&ave);
ll sum=ave*n,ans=;
for(int i=;i<=n;i++)
scanf("%lld%lld",&a[i].a,&a[i].b),sum-=a[i].a;
sort(a+,a+n+);
if(sum<=)
return puts("");
for(int i=;i<=n;i++)
ans+=min(sum,r-a[i].a)*a[i].b,sum-=min(sum,r-a[i].a);
printf("%lld\n",ans);
return ;
}
A. Vanya and Cubes
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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

Output

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

Examples
input
1
output
1
input
25
output
4
Note

Illustration to the second sample:

Codeforces Round #280 (Div. 2) A , B , C的更多相关文章

  1. Codeforces Round #280 (Div. 2) E. Vanya and Field 数学

    E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  2. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分

    D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  3. Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心

    C. Vanya and Exams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  4. Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. CodeForces Round #280 (Div.2)

    A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...

  6. Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...

  7. Codeforces Round #280 (Div. 2)_C. Vanya and Exams

    C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #280 (Div. 2) E. Vanya and Field 思维题

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 预处理

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  10. Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. 【转】NPOI自定义单元格背景颜色

    经常在NPOI群里聊天时发现有人在问NPOI设置单元格背景颜色的问题,而Tony Qu大神的博客里没有相关教程,刚好最近在做项目时研究了一下这一块,在这里总结一下. 在NPOI中默认的颜色类是HSSF ...

  2. C#动态删除控件

    foreach (Control var in panel.Controls) { if (var is Billet) { panel.Controls.Remove(var); var.Dispo ...

  3. git 中 A C D M R T U X 分别解释

    git 中 A C D M R T U X 分别解释 - CSDN博客 https://blog.csdn.net/adminyan/article/details/64922979 A: 你本地新增 ...

  4. JavaScript获取地址栏内容

    例如地址为:http://www.mazey.net/baby/blog/index.php?a=1&b=2#c var query = window.location.href; //htt ...

  5. android自定义控件(四)坐标系

    1.局部坐标系(Local Coordinate) 所谓本地坐标系,就是坐标系以物体的中心为坐标原点,物体旋转.平移等操作都是围绕局部坐标系进行的.这时当物体模型进行旋转.平移等操作时, 局部坐标系也 ...

  6. Beautiful Soup 4.2.0 文档

    Beautiful Soup 4.2.0 文档 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方 ...

  7. django的模板系统过滤器笔记

    -------------------django内建的过滤器-------------------1.add 使用形式为:{{ value | add: "2"}}意义:将val ...

  8. 面向对象编程——super进阶(十)

    一.入门使用 在python中,使用super最常见的让子类继承父类.在这种情况下,当前类和对象可以作为super函数的参数使用,调用函数返回的任何方法都是调用超类的方法,而不是当前类的方法. cla ...

  9. LeetCode:平衡二叉树【110】

    LeetCode:平衡二叉树[110] 题目描述 给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1. 示例 ...

  10. POJ 3468 A Simple Problem with Integers 【线段树】

    题目链接 http://poj.org/problem?id=3468 思路 线段树 区间更新 模板题 在赋初始值的时候,按点更新区间就可以 AC代码 #include <cstdio> ...