Doing Homework again
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<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct WORK
{
int t;
int s;
}wok[1010];
int cmp(WORK a,WORK b)
{
return a.s>b.s;
}
int main()
{
int t,n,i,j,sum,a[1010],flag;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&wok[i].t);
for(i=0;i<n;i++)
scanf("%d",&wok[i].s);
sort(wok,wok+n,cmp);
/*for(i=0;i<n;i++)
printf("%d ",wok[i].t);
printf("\n");
for(i=0;i<n;i++)
printf("%d ",wok[i].s);*/
sum=0;
for(i=0;i<n;i++)
{
if(a[wok[i].t]==0)
{
a[wok[i].t]=1;
continue;
}
if(a[wok[i].t]!=0)
{
flag=0;
for(j=wok[i].t-1;j>0;j--)
{
if(a[j]==0)
{
a[j]=1;
flag=1;
break;
}
}
if(flag==0)
sum+=wok[i].s;
}
}
printf("%d\n",sum);
}
return 0;
}