codeforces 1574 C. Slay the Dragon

在Slay the Dragon游戏中,玩家需要使用英雄击败龙。每只龙有防御x和攻击y,英雄们有不同强度。要击败龙,必须选择至少强于x的英雄去杀龙,并确保剩下英雄的总强度大于等于y。通过花费金币提升英雄的强度。题目要求找到击败每只龙所需的最小金币数。通过排序英雄的强度并使用二分查找,可以计算出每个独立询问的答案。
摘要由CSDN通过智能技术生成

本场比赛其他题目题解

A. Regular Bracket Sequences
B. Combinatorics Homework
C. Slay the Dragon
D. The Strongest Build

C. Slay the Dragon

开启传送门

题目描述

Recently, Petya learned about a new game “Slay the Dragon”. As the name suggests, the player will have to fight with dragons. To defeat
a dragon, you have to kill it and defend your castle. To do this, the player has a squad of n n n heroes, the strength of the i i i-th hero is equal to a i a_i ai.

According to the rules of the game, exactly one hero should go kill the dragon, all the others will defend the castle. If the dragon’s defense is equal to x x x, then you have to send a hero with a strength of at least x x x to kill it. If the dragon’s attack power is y y y, then the total strength of the heroes defending the castle should be at least y y y.

The player can increase the strength of any hero by 1 1 1 for one gold coin. This operation can be done any number of times.

There are m m m dragons in the game, the i i i-th of them has defense equal to x i x_i xi and attack power equal to y i y_i yi. Petya was wondering what is the minimum number of coins he needs to spend to defeat the i i i-th dragon.

Note that the task is solved independently for each dragon (improvements are not saved).

Input

The first line contains a single integer n n n ( 2 ≤ n ≤ 2 ⋅ 1 0 5 2\le n\le 2⋅10^5 2n210

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

zuhiul

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

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

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

打赏作者

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

抵扣说明:

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

余额充值