Doing Homework again

Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 23   Accepted Submission(s) : 21


Problem 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 reduced 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 reduced scores.


 



Output


For each test case, you should output 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 C语言程序代码


/*
题意::
  给出作业数和作业上交的的日期,以及作业的分数,如不能按时完成就扣掉这门作业的分数计算
  每天只能完成一门作业,计算扣掉的最少分数。 
  先给一个数T表示下面可输入几组数据。然后每组数据第一行为一个数N,表示有几门作业
  下面有两行数据,第一行表示每门作业上交的时间,第二行表示没门作业的分数。
解题思路::
  为了扣分最少,那么分数多的作业就必须要完成,将作业按分数从大到小排序,定义一个数组来记录
  当天是否会写作业,若写将其记录为1,将分数最大的在规定日期的当天完成,若在同一天要完成两门
  分数较高的(比其他作业的分数高),就让其在前一天完成,后面的以此类推。推到最后,剩下的就
  是分数小的作业,如果在它规定的日期之前已经排满了要完成的作业,证明他已经被舍弃,将其后面的
  分数加起来,最后得的和几为最小。 
*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct zz
{
 int d,f;
}a[1100];
bool cmp(zz x,zz y)
{
  return x.f>y.f;
}
int b[1001];
int main(){
 int t,n,m,i,j,k,l;
 scanf("%d",&t);
 while(t--)
 {
  memset(b,0,sizeof(b));
  scanf("%d",&n);
  for(i=0;i<n;i++)
   scanf("%d",&a[i].d);
  for(i=0;i<n;i++)
   scanf("%d",&a[i].f);
   sort(a,a+n,cmp);
  m=0;
  for(i=0;i<n;i++)
  {
   k=0;
   for(j=a[i].d;j>0;j--)
   {
    if(b[j]==0)
    {
     b[j]=1;
     k=1;
     break;
    }
   }
   if(k==0)
    m+=a[i].f;
  }
  printf("%d\n",m);
  
 }
 return 0;
}