A job week4

Meaning of the questions:
ZJM there are n jobs, each job has its own DDL, if ZJM not done the job before the DDL, then the teacher will deduct this job all the usual points.
So ZJM want to know how to arrange the order of homework to buckle a bit less points as possible.
Please help him!
input:
Input of T test. The first input line is a single integer T, was found in the number of test cases.
Each test case to begin a positive integer N (1 <= N <= 1000), indicates the number of jobs.
Then two lines. The first line contains N integers representing the DDL, the next row containing N integers representing buckle points.
output:
For each test case, you should reduce the output of the minimum total score, each test line.
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
ideas: the
definition of a structure, which is defined ddl and score. Test samples of the input sort, ddl determines the maximum number of starts from the sample, the sample at this time if the node is not marked, can also be described at this time ddl complete this job, this point will be marked. By traversing the point of all ddl and labeled, the final result for the unmarked sum plus score points. The final result output sum.
Code:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
 int ddl;
 int score;
 bool operator<(const node &te) const
 {
  if(score!=te.score)
     return score>te.score;
  return ddl>te.ddl;
 }
};
int main()
{
 int t;
 cin>>t;
 int n;
 while(t--)
 {
  cin>>n;
  int sum=0;
  int vis[1005]={0};
  node a[1005];
  for(int i=0;i<n;i++)
  {
   cin>>a[i].ddl;
  }
  for(int i=0;i<n;i++)
  {
   cin>>a[i].score;
  }
  sort(a,a+n);
  for(int i=0;i<n;i++)
  {
   int flag=0;
    for(int j=a[i].ddl;j>0;j--)
    {
     if(vis[j]==0)
     {
         vis[j]=1;
      flag=1;
      break;
     }
    }
    if(flag==0)
    sum=sum+a[i].score;
   }
  cout<<sum<<endl;
 }
 return 0;
}
Published 19 original articles · won praise 0 · Views 211

Guess you like

Origin blog.csdn.net/weixin_45117273/article/details/104983036