首页 > 代码库 > HDU1789时间贪心
HDU1789时间贪心
Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13883 Accepted Submission(s):
8053
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.
#include<bits/stdc++.h>
using namespace std;
int vis[10005];
struct node
{
int a,b;
}P[1005];
bool cmp(node A,node B)
{
if(A.b==B.b) return A.a>B.a;
else return A.b>B.b;
}
int main()
{
int t,n,m,i,j;
cin>>t;
while(t--){memset(vis,0,sizeof(vis));
cin>>n;int ans=0,sumn=0;
for(i=1;i<=n;++i) cin>>P[i].a;
for(i=1;i<=n;++i) cin>>P[i].b,sumn+=P[i].b;
sort(P+1,P+1+n,cmp);
//for(i=1;i<=n;++i) cout<<P[i].a<<" "<<P[i].b<<endl;
for(i=1;i<=n;++i){
for(j=P[i].a;j>=1;j--){
if(!vis[j]) {vis[j]=1;ans+=P[i].b;break;}
}
}//cout<<ans<<endl;
cout<<sumn-ans<<endl;
}
return 0;
}
HDU1789时间贪心