A. Vanya and Cubes
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputVanya 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.
InputThe first line contains integer n (1?≤?n?≤?104) ― the number of cubes given to Vanya.
OutputPrint the maximum possible height of the pyramid in the single line.
Sample test(s) Input1Output
1Input
25Output
4
题意:水题,问最多能摆多高。
代码清单:
#includeusing namespace std; int main() { int n,sum=0; cin>>n; for(int i=1;;i++) { if(sum+i*(i+1)/2>n) { cout<
B. Vanya and Lanterns
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputVanya 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?
InputThe first line contains two integers n, l (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.
OutputPrint 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.
Sample test(s) Input7 15 15 5 3 7 9 14 0Output2.5000000000Input2 5 2 5Output2.0000000000
题意:水题,求灯照半径的最小值。
代码清单:
#include#include #include using namespace std; int main() { int n,l,a[1005]; cin>>n>>l; for(int i=0;i >a[i]; sort(a,a+n); double dis=a[0]; for(int i=1;i
C. Vanya and Exams
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputVanya 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?
InputThe first line contains three integers n, r, avg (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).
OutputIn the first line print the minimum number of essays.
Sample test(s) Input5 5 4 5 2 4 7 3 1 3 2 2 5Output4Input2 5 4 5 2 5 2Output0题意:贪心题,每次拿文章数少的。
代码清单:
#include#include #include using namespace std; typedef long long ll; struct edge { ll x; ll y; }a[100005]; bool cmp(edge a,edge b) { return a.y >n>>r>>avg; ll sum