Description
Input
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
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
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct zy
{
int day;
int score;
};
bool compare(zy x,zy y)
{
if(x.score==y.score)
return x.day<y.day;//若分数相同,将时间小的放在前面
else
return x.score>y.score;//将分数按从大到小排序
}
int main()
{
int T;
cin>>T;
zy a[2000];
while(T--)
{
int n,i,j;
cin>>n;
int flag[2000]={0};//标志无任务
for(i=0;i<n;i++)
cin>>a[i].day;
for(i=0;i<n;i++)
cin>>a[i].score;
sort(a,a+n,compare);
int sum=0;
for(i=0;i<n;i++)
{
for(j=a[i].day;j>=1;j--)
{
if(flag[j]==0)
{
flag[j]=1;//代表第j天有已经有任务了
break;
}
}
if(j==0)//代表任务未完成
sum+=a[i].score;
}
cout<<sum<<endl;
}
return 0;
}
495



被折叠的 条评论
为什么被折叠?



