hdu 1789

View Code
Problem : 1789 ( Doing Homework again )     Judge Status : Accepted
RunId : 5740019    Language : C++    Author : billforum
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
#include <iostream>
 #include <algorithm>
 #include <stdio.h>

 using namespace std;
 
 const int N=1005;
 struct node
 {
     int d;
     int w;
 };
 node nd[N];
 bool td[N];
 bool cmp(node x,node y)
 {
     if(x.w==y.w)
     {
         return (x.d<y.d);
     }
     else return(x.w>y.w);
 }
 int main()
 {
     int t,n;
    int ans;
     cin>>t;
     while(t--)
     {
         ans=0;
         scanf("%d",&n);
         for(int i=0;i<n;i++)
                 scanf("%d",&nd[i].d);
            
         for(int i=0;i<n;i++)
             scanf("%d",&nd[i].w);    
        sort(nd,nd+n,cmp);    
        
        for(int i=1;i<N;i++)
            td[i]=1;
            td[0]=1;
        for(int i=0;i<n;i++)
        {
            int tmp=nd[i].d;
            if(td[tmp]==1)
            td[tmp]=0;
            else
            {
                while(td[tmp]==0)
                    tmp--;
                if(tmp==0) ans+=nd[i].w;
                else td[tmp]=0;
            }
        }
     printf("%d\n",ans);
     
     }
         return 0;
 }
posted @ 2012-04-09 21:11  wuzhibin  阅读(346)  评论(0)    收藏  举报