HDU 1789 doing homework again (Greedy)

Source: Internet
Author: User

A large competition in ACM is coming back. Many homework. Each assignment has a deadline. If it is not completed within the deadline, the corresponding score will be deducted. How many points will be deducted?

Sort all jobs in ascending order of the number of points deducted. Then, greedy. If you can finish the previous job, you will be able to deduct points if you cannot ~

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N = 1005;int dli[N], red[N], k[N], cas, ans, n;bool vis[N];bool cmp (int i, int j){    return red[i] > red[j];}int main(){    scanf ("%d", &cas);    while (cas--)    {        ans = 0;        memset (vis, 0, sizeof (vis));        scanf ("%d", &n);        for (int i = 1; i <= n; ++i)            scanf ("%d", &dli[i]), k[i] = i;        for (int j = 1; j <= n; ++j)            scanf ("%d", &red[j]);                    sort (k + 1, k + n + 1, cmp);        for (int i = 1, j; i <= n; ++i)        {            for (j = dli[k[i]]; j >= 1; --j)                if (!vis[j])                {                    vis[j] = 1;                    break;                }            if (j == 0) ans += red[k[i]];        }        printf ("%d\n", ans);    }    return 0;}

Doing homework again
Problem descriptionignatius has just come back school from the 30th ACM/ICPC. now he has a lot of homework to do. every teacher gives him a deadline of handing in the homework. if Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. and now we assume that doing everyone homework always takes one day. so Ignatius wants you to help him to arrange the order of doing homework to minimize the specified CED score.
Inputthe input contains several test cases. The first line of the input is a single integer t that is the number of test cases. t test cases follow.
Each test case start with a positive integer N (1 <= n <= 1000) which indicate the number of homework .. then 2 lines follow. the first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the specified CED scores.
 
Outputfor each test case, You shoshould output the smallest total balanced CED score, one line per test case.
 
Sample Input
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
 
Sample output
035
 


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.