CF 750A New Year and Hurry

在这篇博客中,作者介绍了如何在一场持续四小时的编程竞赛中,解决最多的问题,以便在新年前夕的派对前赶到。比赛包含难度不等的n个问题,每个问题需要5*i分钟来解决,而从比赛地点到派对现场需要k分钟。通过计算,确定了在确保能参加派对的情况下,参赛者最多能解决的问题数量。

A. New Year and Hurry
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem.

Limak’s friends organize a New Year’s Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.

How many problems can Limak solve if he wants to make it to the party?

Input
The only line of the input contains two integers n and k (1 ≤ n ≤ 10, 1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.

Output
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.

Examples
inputCopy
3 222
outputCopy
2
inputCopy
4 190
outputCopy
4
inputCopy
7 1
outputCopy
7
Note
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn’t have enough time to solve 3 problems so the answer is 2.

In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.

数列
解题思路:等差数列求和公式

#include<iostream>
#include<cstdlib>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{

	int n,time,i;
	cin >> n >> time;
	for(i = 0;i<n;i++)
	if((i+1)*(i+2)/2*5>240-time)break;
	cout<<i<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值