Doing Homework again
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7097 Accepted Submission(s): 4207
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
第一次做贪心的题,不知道咋办,模仿人家的思路,感觉有点像DP和背包问题,但还是拿不准,
*/
#include<cstdio>
#include<cstring>#include<cstdlib>
#include<algorithm>
using namespace std;
struct node
{
int day;
int score;
}work[1010];
int used[1010];
int cmp(node a,node b)
{
return a.score>b.score;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i,j,t,sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&work[i].day);
for(i=0;i<n;i++)
scanf("%d",&work[i].score);
sort(work,work+n,cmp);
memset(used,0,sizeof(used));
for(i=0;i<n;i++)
{
t=work[i].day;
while(t&&used[t])
t--;
if(!t)
sum+=work[i].score;
else
used[t]=1;
}
printf("%d\n",sum);
}
return 0;
}
/*
他人的代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct node
{
int day;
int score;
}work[1010];
int used[1010];//记录当天是否被占用
int cmp(node a,node b)
{
return a.score>b.score;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i,j,sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&work[i].day);
for(i=1;i<=n;i++)
scanf("%d",&work[i].score);
sort(work+1,work+n+1,cmp);
memset(used,0,sizeof(used));
for(i=1;i<=n;i++)
{
for(j=work[i].day;j>=1;j--)
if(!used[j])
{
used[j]=1;
break;
}
if(j==0)
sum+=work[i].score;
}
printf("%d\n",sum);
}
return 0;
}
*/