当前位置:网站首页>GYM103660L.Monster Tower 整体二分
GYM103660L.Monster Tower 整体二分
2022-07-17 22:29:00 【HeartFireY】
GYM103660L.Monster Tower
题目思路
有一个高 n n n层的塔,塔的每层有一个怪兽,怪兽拥有 a i a_i ai的血量,初始血量为 x x x,击败第 i i i层后可以获得该层怪兽的血量(即 x + = a [ i ] x += a[i] x+=a[i]),当且仅当 x ≥ a [ i ] x \geq a[i] x≥a[i]时才可以击败该怪兽。每次只能选择底 k k k层的怪兽进行攻击。问最小的 x x x。
容易发现答案具有单调性,因此考虑二分答案。 c h e c k check check的时候使用优先队列维护底 k k k层的怪兽血量,当堆顶的血量大于当前血量时不合法。
数组是2e5
Code
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10;
int a[N], s[N];
inline void solve(){
int n = 0, k = 0; cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
auto check = [&](int mid){
priority_queue<int, vector<int>, greater<int>> pq;
int stn = mid;
int pos = 1; while(pos <= k) pq.emplace(a[pos++]);
while(pq.size()){
if(stn < pq.top()) return false;
else{
stn += pq.top();
pq.pop();
if(pos <= n) pq.emplace(a[pos++]);
}
}
return true;
};
int l = 0, r = *max_element(a + 1, a + 1 + n), ans = 0;
while(l <= r){
int mid = l + r >> 1;
if(check(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
int t = 1; cin >> t;
while(t--) solve();
return 0;
}
边栏推荐
- CompositionAPI 组件开发范式
- 模块1 作业
- 见鬼,U盘空间怎么少了,原来是EFI分区搞的鬼,删除它
- Code runner for vs code, with more than 40million downloads! Support more than 50 languages
- 2. MySQL introduction
- ICML2022 | 幾何多模態對比錶示學習
- Istio XDS配置生成实现
- 国科大. 深度学习. 期末试题与简要思路分析
- 国内顶尖专家集聚广州,探讨健康医疗数据安全应用
- Several points to be analyzed in the domestic fpga/dsp/zynq scheme
猜你喜欢

6U VPX high speed signal processing board based on ku115+mpsoc (xcku115 + zu9eg +dsp)

Deployment 原理

Cilium & Hubble

Authing practice | unified management solution for manufacturing identity authentication

【微服务】 微服务学习笔记三:利用Feign替换RestTemplate完成远程调用

MySQL view

Module 1 job

Leetcode 1275. Find out the winner of tic tac toe

抽象類與派生類

Leetcode 1296. 划分数组为连续数字的集合(已解决)
随机推荐
High performance pxie data preprocessing board based on kinex ultrascale series FPGA (ku060 +fmc sub card interface)
最大堆与堆排序和优先队列
OSError: sndfile library not found 解决方案
Deployment 原理
csrf防护机制
TDesign CompositionAPI 重构之路
Natural language processing model of bigscience open source bloom
2. MySQL introduction
6U VPX high speed signal processing board based on ku115+mpsoc (xcku115 + zu9eg +dsp)
[flask introduction series] request hook and context
Comparaison de deux types de machines virtuelles
实习是步入社会的一道坎
Istio XDS configuration generation implementation
Behind the high salary of programmers' operation and maintenance
CompositionAPI 组件开发范式
SBOM(Software Bill of Materials,软件物料清单)
Oracle - 锁
Practice of tDesign in vitest
BigScience 开源 Bloom 的自然语言处理模型
Zabbix实现对Redis的监控