Summer Camp (2) Eighth bomb-----Hero (hdu4310)

Source: Internet
Author: User
Tags dota

K-hero

crawling in process ... crawling failed time limit:3000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64u

Submit Status

Description

When the playing DotA with god-like rivals and Pig-like team members, you had to face an embarrassing situation:all your tea Mmates is killed, and you had to fight 1vN.

There is the key attributes for the heroes in the game, Health Point (HP) and damage per shot (DPS). Your hero has almost infinite HP and only 1 DPS.

To simplify the problem, we assume the game was turn-based, but not real-time. In each round, you can choose one enemy hero to attack, and his HP would decrease by 1. While in the same time, all the lived enemy heroes would attack you, and your HP would decrease by the sum of their DPS. If one hero ' s HP fall equal to (or below) zero, he'll die after this round, and cannot attack your in the following round S.

Although your hero is undefeated, you want to choose best strategy to kill all the enemy heroes with minimum HP loss.

Input

The first line of all test case contains the number of enemy heroes N (1 <= n <= 20). Then N lines followed, each contains integers DPSi and HPi, which is the DPS and HP for each hero. (1 <= DPSi, HPi <= 1000)

Output

Output one line for each test, indicates the minimum HP loss.

Sample Input

110 22100 11 100

Sample Output

20201 problem Analysis: DotA ah, long time no play, really ... Well, first count all the enemy damage, and then use DPS/HP (each point of health damage) as the basis for sorting, from large to small to kill the light, each kill a will let the total DP minus the killed person's DP can.
1#include"iostream"2#include"algorithm"3 4 using namespacestd;5 structEnemy6 {7     intHP;8     intDP;9 };TenEnemy n[ +]; OneEnemy t[ +]; A intsum; - __int64 dead; - voidEbegin (intN) the { -    for(intI=1; i<=n;i++) -     { -Cin>>n[i].dp>>n[i].hp; +Sum + =N[I].DP; -     } + } A voidDefeat (intN) at { -    for(intI=1; i<=n;i++) -   { -Dead + = sum *n[i].hp; -Sum-=N[I].DP; -   } incout<<dead<<Endl; - } to intcompare (enemy X,enemy y) + { -     returnX.HP * Y.DP < X.DP *y.hp; the } * intMain () $ {Panax Notoginseng     intN; -      while(cin>>N) the     { +Dead =0; A ebegin (n); theSort (n+1, n+n+1, compare); + defeat (n); -     } $     return 0; $}
View Code

Summer Camp (2) Eighth bomb-----Hero (hdu4310)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.