Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8208 Accepted Submission(s): 4834
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.
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
0 3 5
#include<string>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
double deadline;
double reduce;
}num[1200];
int t,n;
int comp(node a, node b)
{
return a.reduce>b.reduce;
}
int main()
{
cin>>t;
while(t--)
{
cin>>n;
int k;
for(int i=0;i<n;i++)
{
cin>>k;
num[i].deadline=k*1.0;
}
for(int i=0;i<n;i++)
{
cin>>k;
num[i].reduce=k*1.0;
}
sort(num,num+n,comp);
int sum=0;
int mark[1001];
int j;
memset(mark,0,sizeof(mark));
for(int i=0;i<n;i++)
{
for(j=num[i].deadline;j>=1;j--)
{
if(!mark[j])
{
mark[j]=1;
break;
}
}
if(j==0)
sum+=num[i].reduce;
}
cout<<sum<<endl;
}
}