当前位置:网站首页>【堆】小红的数组
【堆】小红的数组
2022-08-01 03:45:00 【暮色_年华】
小红拿到了一个数组a ,每次操作小红可以选择数组中的任意一个数减去 ,小红一共能进行 k 次。
小红想在 k 次操作之后,数组的最大值尽可能小。请你返回这个最大值。
每次必须选择最大的减去,否则,最大值不会变,那么这次操作没有收益。
所以可以使用最大堆,可以自动维护数组的最大值。
建堆后,出堆k次并更新即可。
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param a int整型ArrayList
* @param k int整型
* @param x int整型
* @return int整型
*/
public int minMax (ArrayList<Integer> a, int k, int x) {
// write code here
PriorityQueue<Integer>q=new PriorityQueue<>(Collections.reverseOrder());
for(int i=0;i<a.size();i++){
q.add(a.get(i));
}
for(int i=0;i<k;i++){
int n=q.poll();
n-=x;
q.add(n);
}
return q.peek();
}
}边栏推荐
- Which interpolation is better for opencv to zoom in and out??
- 开源许可证 GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
- [FPGA tutorial case 43] Image case 3 - image sobel edge extraction through verilog, auxiliary verification through MATLAB
- HCIP(15)
- /etc/fstab
- Lua introductory case of actual combat 1234 custom function and the standard library function
- leetcode6133. 分组的最大数量(中等)
- [kali-information collection] enumeration - DNS enumeration: DNSenum, fierce
- Software Testing Interview (3)
- Difference Between Compiled and Interpreted Languages
猜你喜欢

button remove black frame

Introduction to Oracle

【愚公系列】2022年07月 Go教学课程 024-函数
![[kali-information collection] enumeration - DNS enumeration: DNSenum, fierce](/img/97/bbe7c2af0ff8bcb5222b9105d80c73.png)
[kali-information collection] enumeration - DNS enumeration: DNSenum, fierce

二舅

情人节浪漫3D照片墙【附源码】

每周小结(*67):为什么不敢发表观点

【搜索专题】看完必会的BFS解决最短路问题攻略

《少年派2》:新男友竟脚踩两只船,林妙妙与钱三一感情回温

Passive anti-islanding-UVP/OVP and UFP/OFP passive anti-islanding model simulation based on simulink
随机推荐
Compiled on unbutu with wiringPi library and run on Raspberry Pi
win10 fixed local IP
简单易用的任务队列-beanstalkd
Introduction to the Elastic Stack
《少年派2》:新男友竟脚踩两只船,林妙妙与钱三一感情回温
树莓派 的 arm 版的 gcc 安装 和环境变量的配置
Flutter Tutorial 01 Configure the environment and run the demo program (tutorial includes source code)
What is a programming language
Which interpolation is better for opencv to zoom in and out??
JS new fun(); 类与实例 JS基于对象语言 只能通过书写构造函数充当类
The fledgling Xiao Li's 114th blog project notes: Wisdom cloud intelligent flower watering device combat (3) - basic Demo implementation
second uncle
Ordinary users cannot access HGFS directory
IJCAI2022 | Hybrid Probabilistic Reasoning with Algebraic and Logical Constraints
【愚公系列】2022年07月 Go教学课程 023-Go容器之列表
MySQL3
button去除黑框
The fledgling Xiao Li's 112th blog project notes: Wisdom cloud intelligent flower watering device actual combat (1) - basic Demo implementation
初出茅庐的小李第112篇博客项目笔记之机智云智能浇花器实战(1)-基础Demo实现
纽约大学等 | TM-Vec:用于快速同源检测和比对的模版建模向量