HDU-1789 doing homework again

Source: Internet
Author: User

Description

Ignatius 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.

Input

The 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.
 

Output

For each test case, You shocould output the smallest total 0000ced 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

Question: each assignment has a specified time to complete, and the time-out points are deducted for minimum points.

Idea: greedy sorting, and then each one starts from the farthest time, marking the Processing

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1005;struct Node {int day, cost;} node[maxn];int n;int f[maxn];int cmp(Node a, Node b) {return a.cost < b.cost;}int main() {int t;scanf("%d", &t);while (t--) {scanf("%d", &n);for (int i = 0; i < n; i++) {scanf("%d", &node[i].day);if (node[i].day > n)node[i].day = n;}int sum = 0;for (int i = 0; i < n; i++) {scanf("%d", &node[i].cost);sum += node[i].cost;}sort(node, node+n, cmp);memset(f, 0, sizeof(f));for (int i = n-1; i >= 0; i--) for (int j = node[i].day; j >= 1; j--) if (!f[j]) {f[j] = 1;sum -= node[i].cost;break;}printf("%d\n", sum);}return 0;}



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.