最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Leetcode 2383. Minimum Hours of Training to Win a Competition

2023-03-14 12:56 作者:您是打尖兒還是住店呢  | 我要投稿

You are entering a competition, and are given two?positive?integers?initialEnergy?and?initialExperience?denoting your initial energy and initial experience respectively.

You are also given two?0-indexed?integer arrays?energy?and?experience,

both of length?n.

You will face?n?opponents?in order.?

The energy and experience of the?ith?opponent is denoted by?energy[i]?and?experience[i]?respectively.

When you face an opponent, you need to have both?strictly?greater experience and energy to defeat them and move to the next opponent if available.

Defeating the?ith?opponent?increases?your experience by?experience[i], but?decreases?your energy by?energy[i].

Before starting the competition,?

you can train for some number of hours.?

After each hour of training, you can?either?choose to increase your initial experience by one, or increase your initial energy by one.

Return?the?minimum?number of training hours required to defeat all?n?opponents.

?

Example 1:

Input: initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]

Output: 8

Explanation: You can increase your energy to 11 after 6 hours of training,?

and your experience to 5 after 2 hours of training.?

You face the opponents in the following order:?

- You have more energy and experience than the 0th opponent so you win. ?

Your energy becomes 11 - 1 = 10,?

and your experience becomes 5 + 2 = 7.

- You have more energy and experience than the 1st opponent so you win. ?

Your energy becomes 10 - 4 = 6, and your experience becomes 7 + 6 = 13.?

- You have more energy and experience than the 2nd opponent so you win. ?

Your energy becomes 6 - 3 = 3, and your experience becomes 13 + 3 = 16.?

- You have more energy and experience than the 3rd opponent so you win.?

?Your energy becomes 3 - 2 = 1, and your experience becomes 16 + 1 = 17.?

You did a total of 6 + 2 = 8 hours of training before the competition, so we return 8. It can be proven that no smaller answer exists.

Example 2:

Input: initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]Output: 0Explanation:?

You do not need any additional energy or experience to win the competition, so we return 0.

?

Constraints:

  • n == energy.length == experience.length

  • 1 <= n <= 100

  • 1 <= initialEnergy, initialExperience, energy[i], experience[i] <= 100

一開(kāi)始理解錯(cuò)意思了,其實(shí)就是按順序即可,另一個(gè)就是每次計(jì)算出差異,hours累加。



Runtime:?0 ms, faster than?100.00%?of?Java?online submissions for?Minimum Hours of Training to Win a Competition.

Memory Usage:?41.9 MB, less than?41.15%?of?Java?online submissions for?Minimum Hours of Training to Win a Competition.


Leetcode 2383. Minimum Hours of Training to Win a Competition的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
施甸县| 安多县| 陇川县| 康保县| 绥阳县| 上饶市| 江门市| 博野县| 郓城县| 德格县| 湛江市| 犍为县| 兰考县| 舒城县| 新田县| 乌鲁木齐市| 鱼台县| 青神县| 济宁市| 五寨县| 原平市| 云南省| 长沙市| 平原县| 巴青县| 南召县| 临澧县| 赤壁市| 敦化市| 山西省| 莱芜市| 江口县| 汪清县| 闽侯县| 湖口县| 秦安县| 唐海县| 武夷山市| 保靖县| 张北县| 桦南县|