Xidianoj 1120 Gold of Orz Pandas

Source: Internet
Author: User

Title Description

Orz Panda is addicted to one RPG game. To make his character stronger, he has to fulfil tasks to get EXP for higher level. At first he accepted all the tasks. But after he read the rules carefully, he realized the what he had done is stupid.
Rule:
Every task costs 1 time interval.
Every task has a dead line. If you can ' t finish it in time, you had to pay the same amount of gold as the EXP given by this task.

Orz Panda wants to know the minimum amount of gold he have to pay.

Input

The first line has a one integer n, tell what many tasks Orz Panda has accepted.
The second line had n integers ti separated by blank and represent for the ith task ' s dead line.
The third line had n integers ei separated by blank, represent for the
EXP given by the ith task.
(1 <= N, ti, ei <= 1000)

Output

One integer for the minimum amount of gold Orz Panda have to pay.

--The first idea of the body is greed, think of the value of the row to be greedy seems to be right, try it really so
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>using namespacestd;structtasknode{intDeadLine; intValue;};structTasknode task[1001];intused[1001];BOOLcmpstructTasknode T1,structTasknode T2) {    if(t1. Value = = t2. Value)return(t1. DeadLine <T2.    DeadLine); returnT1. Value >T2. Value;}intMain () {intN;  while(SCANF ("%d", &n)! =EOF) {        inti;  for(i=1; i<=n;i++) {scanf ("%d",&Task[i].        DeadLine); }         for(i=1; i<=n;i++) {scanf ("%d",&Task[i].        Value); } sort (Task+1, task+1+n,cmp); intAns =0; memset (Used,0,sizeof(used));  for(i=1; i<=n;i++){            intNowT =Task[i].            DeadLine;  while(NowT >0&& Used[nowt]) nowt--; if(NowT = =0) {Ans+=Task[i].            Value; }             ElseUSED[NOWT] =1; } printf ("%d\n", Ans); }    return 0;}

Xidianoj 1120 Gold of Orz Pandas

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.