当前位置:网站首页>GYM103660L. Monster tower overall dichotomy
GYM103660L. Monster tower overall dichotomy
2022-07-19 15:11:00 【HeartFireY】
GYM103660L.Monster Tower
Topic ideas
There is a high n n n Tower on the first floor , There is a monster on each floor of the tower , Monsters have a i a_i ai HP , Initial health is x x x, Defeat number i i i After this layer, you can get the blood volume of the monster in this layer ( namely x + = a [ i ] x += a[i] x+=a[i]), If and only if x ≥ a [ i ] x \geq a[i] x≥a[i] Only then can we defeat the monster . Only the bottom can be selected at a time k k k Tier monsters attack . Ask the smallest x x x.
It is easy to find that the answer is monotonous , So consider the dichotomous answer . c h e c k check check When using the priority queue to maintain the bottom k k k The monster's HP of layer , It is illegal when the health at the top of the heap is greater than the current health .
An array is 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;
}
边栏推荐
- MongoDB分片集群搭建
- 2. MySQL introduction
- 国内顶尖专家集聚广州,探讨健康医疗数据安全应用
- Leetcode 1275. 找出井字棋的获胜者
- ICML2022 | 幾何多模態對比錶示學習
- MySQL CPU usage is soaring. How to locate who is occupying it
- 第1章 预备知识
- 实习是步入社会的一道坎
- Code Runner for VS Code,下载量突破 4000 万!支持超过50种语言
- Is it safe to buy funds in a securities account? I want to make a fixed investment in the fund
猜你喜欢

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

Unveil the mystery of service grid istio service mesh

Scheduled tasks, VIM directly creates and modifies users

SQL wrong questions set of Niuke brush questions

Comparaison de deux types de machines virtuelles

A - trees on the level

ZABBIX realizes the monitoring of redis
![[flask introduction series] request hook and context](/img/a9/96e330525ee1337daab275b87db892.png)
[flask introduction series] request hook and context

FPGA (VGA Protocol Implementation)

PCIe Cameralink signal generator (Cameralink image analog source)
随机推荐
Oracle - 锁
Comparaison de deux types de machines virtuelles
人脸技术:不清楚人照片修复成高质量高清晰图像框架(附源代码下载)
Field programmable logic gate array FPGA
Maximum heap and heap sort and priority queue
C - Matrix Chain Multiplication(栈的应用)
2022 P gas cylinder filling examination practice questions simulated examination platform operation
通过授权微信,达到软件登录账号的效果~~未完
Integrated video processing card based on Fudan micro FPGA + Huawei hisilic hi3531dv200 + Mji innovative MCU
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)
微信小程序9-发布代码
Force deduction 912 sorting array notes
最大堆与堆排序和优先队列
MongoDB分片集群搭建
Code runner for vs code, with more than 40million downloads! Support more than 50 languages
Notes on random nodes of force buckle 382 linked list
GYM103660E.Disjoint Path On Tree 树上计数
Chapter 1 preliminary knowledge
C - matrix chain multiplexing (Application of stack)