Doing Homework again
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 6961 Accepted Submission (s): 4145
Problem Description Ignatius have just come back school from the 30th ACM/ICPC. Now he had 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 would reduce his score of the final Test. And now we assume this doing everyone homework always takes one day. So Ignatius wants-to-help him to arrange the order of doing homework to minimize the reduced score.
Input the input contains several test cases. The first line of the input was a single integer T so 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 this indicate the deadlines of the subjects, and the next line contains N integers that Indicate the reduced scores.
Output for each test case, you should output of the smallest total reduced score, one line per test case.
Sample Input
3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4
Sample Output
0 3 5
Author LCY
/*
greedy, refueling ...
time:2014-11-1 9:20
* *
#include <cstdio>
#include <cstring>
#include < Algorithm>
using namespace std;
#define MAX 1010
struct h{
int time;
int scor;
} S[max];
BOOL CMP (H a,h b) {
if (A.scor>b.scor) return true;
else if (a.scor==b.scor&&a.time<b.time) return true;
return false;
}
BOOL Vis[max];
int main () {
int t,n;
scanf ("%d", &t);
while (t--) {
memset (s,0,sizeof (s));
memset (vis,0,sizeof (Vis));
scanf ("%d", &n);
for (int i=0;i<n;i++)
scanf ("%d", &s[i].time);
for (int i=0;i<n;i++)
scanf ("%d", &s[i].scor);
Sort (s,s+n,cmp);
int i,j,ans=0;
for (i=0;i<n;i++) {for
(j=s[i].time;j>0;j--) {//j cannot be equal to 0
if (vis[j]==0) {
vis[j]=true;
break;
}
}
if (j==0)
Ans+=s[i].scor;
}
printf ("%d\n", ans);
}
return 0;
}