CF1042A Benches

本文解析了CodeForces竞赛中A类题目“长凳”的解题思路与代码实现。介绍了如何通过排序来找到使额外进入公园的人数达到最大与最小分布的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题链接:http://codeforces.com/contest/1042/problem/A

Benches

There are n n n benches in the Berland Central park. It is known that a i a_i ai people are currently sitting on the i i i-th bench. Another m m m people are coming to the park and each of them is going to have a seat on some bench out of n n n available.

Let k k k be the maximum number of people sitting on one bench after additional m m m people came to the park. Calculate the minimum possible k k k and the maximum possible k k k.

Nobody leaves the taken seat during the whole process.

Input

The first line contains a single integer n ( 1 ≤ n ≤ 100 ) n(1≤n≤100) n(1n100) — the number of benches in the park.

The second line contains a single integer m ( 1 ≤ m ≤ 10000 ) m(1≤m≤10000) m(1m10000) — the number of people additionally coming to the park.

Each of the next n n n lines contains a single integer a i ( 1 ≤ a i ≤ 100 ) a_i(1≤a_i≤100) ai(1ai100) — the initial number of people on the i i i-th bench.

Output

Print the minimum possible k k k and the maximum possible k k k, where k k k is the maximum number of people sitting on one bench after additional m m m people came to the park.

Examples
input

4
6
1
1
1
1

output

3 7

input

1
10
5

output

15 15

input

3
6
1
6
5

output

6 12

input

3
7
1
6
5

output

7 13

Note

In the first example, each of four benches is occupied by a single person. The minimum k k k is 3 3 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum k k k is 7 7 7. That requires all six new people to occupy the same bench.

The second example has its minimum k k k equal to 15 15 15 and maximum k k k equal to 15 15 15, as there is just a single bench in the park and all 10 10 10people will occupy it.

题解

我都不知道我为什么要排序 (可能是身处排序强校的缘故吧)

代码
#include<bits/stdc++.h>
using namespace std;
int a[105],maxn,n,m;
void in(){scanf("%d%d",&n,&m);for(int i=1;i<=n;++i)scanf("%d",&a[i]);}
void ac()
{
	sort(a+1,a+1+n);maxn=a[n]+m;
	for(int i=1;i<=n;++i)m-=a[n]-a[i];
	if(m<0)printf("%d",a[n]);
	else printf("%d",a[n]+m/n+(bool)(m%n));
	printf(" %d",maxn);
}
int main(){in();ac();}
### 如何在Quartus Prime 中添加或创建 Test Benches #### 创建Testbench 对于希望在 Quartus Prime 中启动测试平台模板编写工具的情况,可以通过导航至 `Processing` 菜单中的 `Start` 子菜单来实现这一目标。具体来说,在该子菜单下选择 `Start Test Bench Template Writer` 可以开启用于生成测试平台模板的工作流[^1]。 #### 编写待测程序与测试程序 针对具体的硬件描述语言项目,比如这里提到的一个八位全加器的设计案例,首先应当完成 `.v` 文件的编写工作作为被验证模块。随后,通过上述提及的方法获取到由软件自动生成的测试文件模板(`.vt`),再基于此模板进一步开发详细的测试激励信号逻辑以便充分检验设计的功能正确性[^2]。 #### 配置ModelSim仿真环境 当涉及到 ModelSim 的集成设置时,则需遵循如下操作流程: - 进入 `Assignments` 下拉列表里的 `Settings...` 项; - 定位到左侧树形结构视图内的 Simulation 分支,并调整右侧区域显示的相关参数设定——特别是要指定 Tool Name 字段为 ModelSim 并勾选 Compile Test Bench 复选框; - 利用弹出对话框中的 New 按钮定义新的测试平台条目,同时确保关联正确的 `.vt` 测试源码路径; - 继续确认保存所做的更改直至返回主界面。 #### 启动仿真过程 最后一步是在成功完成了前述准备工作之后,按照指引逐步引导工程进入到实际运行阶段。此时应该能够顺利切换到 ModelSim 应用环境中展开波形观察等活动,从而评估电路行为是否满足预期要求。 ```verilog // 示例:简单的Verilog代码片段展示如何实例化DUT (Design Under Test) module tb_full_adder; reg [7:0] a, b; // 输入A和B wire [8:0] sum; // 输出求和结果 full_adder uut ( .a(a), .b(b), .sum(sum) ); initial begin $dumpfile("full_adder.vcd"); $dumpvars(0, tb_full_adder); // 施加不同的输入组合来进行功能验证... a = 8'b0000_0001; b = 8'b0000_0001; #10 a = 8'b0000_0010; b = 8'b0000_0010; #10 $finish; end endmodule ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值