Codeforces Round #143 (Div. 2) C. To Add or Not to Add 胡搞

本文深入探讨了深度学习与人工智能领域的最新进展,包括机器学习算法、神经网络模型、自然语言处理、计算机视觉等多个方面。文章不仅概述了核心概念和技术原理,还提供了实际案例分析,展示了这些技术在解决现实世界问题中的强大能力。

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

A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array.

However, before looking for such number, you are allowed to perform not more than k following operations — choose an arbitrary element from the array and add 1 to it. In other words, you are allowed to increase some array element by 1 no more than k times (you are allowed to increase the same element of the array multiple times).

Your task is to find the maximum number of occurrences of some number in the array after performing no more than k allowed operations. If there are several such numbers, your task is to find the minimum one.

Input

The first line contains two integers n and k (1 ≤ n ≤ 1050 ≤ k ≤ 109) — the number of elements in the array and the number of operations you are allowed to perform, correspondingly.

The third line contains a sequence of n integers a1, a2, ..., an (|ai| ≤ 109) — the initial array. The numbers in the lines are separated by single spaces.

Output

In a single line print two numbers — the maximum number of occurrences of some number in the array after at most k allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces.

Sample test(s)
input
5 3
6 3 4 0 2
output
3 4
input
3 4
5 5 5
output
3 5
input
5 3
3 1 2 2 1
output
4 2
Note

In the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence 6, 4, 4, 0, 4, where number 4 occurs 3 times.

In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array 5, 5, 5, if we increase each by one, we get 6, 6, 6. In both cases the maximum number of occurrences equals 3. So we should do nothing, as number 5 is less than number 6.

In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence 3, 2, 2, 2, 2, where number 2 occurs 4 times.

         题意:给你一个数列(好吧,又是数列= =),可对这个数列中的某些数加一个值,但加的总值不能超过k。求在这些操作下,使得数列中的某个数出现的次数最多。

      这个题纯靠yy,我们可以依次从数列中最小的数开始枚举,但复杂度为O(n^2),铁定超时。但是可以优化之,大大降低复杂度。首先对数列排序,然后依次从左往右开始枚举,那么这里可以有一个状态转移:假设当前状态还剩余d可操作,满足数相等的最左端的数的位置为l,那么新加一个数num[i+1],只要比较(num[i+1]-num[i])*(i-l+1)与d的关系即可,来改变l的位置,那么就能很快求出下一状态。

      My code:

//STATUS:C++_AC_78MS_400KB 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#define LL __int64
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
const int MAX=100010,INF=200000000,MOD=1000000007;
const double esp=1e-6;
int cmp(const void *a,const void *b){
	return *(int*)a - *(int*)b;
}
int num[MAX];
int n;
LL k;

int main()
{
//	freopen("in.txt","r",stdin);
	int i,j,l,max_cou,max_num;
	LL d;
	while(~scanf("%d%I64d",&n,&k))
	{
		for(i=1;i<=n;i++)
			scanf("%d",&num[i]);

		qsort(num+1,n,sizeof(int),cmp);
		l=1;
		max_cou=1,max_num=num[1];
		for(i=2;i<=n;i++){
			d=(LL)(i-l)*(LL)(num[i]-num[i-1]);
			k-=d;
			while(k>0 && l>1 && num[i]-num[l-1]>=k){
				l--;
				k-=num[i]-num[l];
			}
			while(k<0 && l<i){
				k+=num[i]-num[l];
				l++;
			}
			if(i-l+1>max_cou){
				max_cou=i-l+1;
				max_num=num[i];
			}
		}
		
		printf("%d %d\n",max_cou,max_num);
	}
    return 0;
}

资源下载链接为: https://pan.quark.cn/s/1bfadf00ae14 “STC单片机电压测量”是一个以STC系列单片机为基础的电压检测应用案例,它涵盖了硬件电路设计、软件编程以及数据处理等核心知识点。STC单片机凭借其低功耗、高性价比和丰富的I/O接口,在电子工程领域得到了广泛应用。 STC是Specialized Technology Corporation的缩写,该公司的单片机基于8051内核,具备内部振荡器、高速运算能力、ISP(在系统编程)和IAP(在应用编程)功能,非常适合用于各种嵌入式控制系统。 在源代码方面,“浅雪”风格的代码通常简洁易懂,非常适合初学者学习。其中,“main.c”文件是程序的入口,包含了电压测量的核心逻辑;“STARTUP.A51”是启动代码,负责初始化单片机的硬件环境;“电压测量_uvopt.bak”和“电压测量_uvproj.bak”可能是Keil编译器的配置文件备份,用于设置编译选项和项目配置。 对于3S锂电池电压测量,3S锂电池由三节锂离子电池串联而成,标称电压为11.1V。测量时需要考虑电池的串联特性,通过分压电路将高电压转换为单片机可接受的范围,并实时监控,防止过充或过放,以确保电池的安全和寿命。 在电压测量电路设计中,“电压测量.lnp”文件可能包含电路布局信息,而“.hex”文件是编译后的机器码,用于烧录到单片机中。电路中通常会使用ADC(模拟数字转换器)将模拟电压信号转换为数字信号供单片机处理。 在软件编程方面,“StringData.h”文件可能包含程序中使用的字符串常量和数据结构定义。处理电压数据时,可能涉及浮点数运算,需要了解STC单片机对浮点数的支持情况,以及如何高效地存储和显示电压值。 用户界面方面,“电压测量.uvgui.kidd”可能是用户界面的配置文件,用于显示测量结果。在嵌入式系统中,用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值