Fear of thinking and practice of [programming] A DDL operation of Week4

Subject description:

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.

Input formats:

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.

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

Output formats:

For each test case, the output should decrease the minimum total score, each test line.

Sample Output:

0
3
5

Sample Description:

There are three sets of examples above.
For the first set of samples, there are three jobs DDL their third day, ZJM do all done in just a day before the DDL, so no points, 0 is output.
For the second set of sample, there are three jobs, they are DDL the first day, the third day, the first day. ZJM made on the first day of a job, a second job done the next day, a total of 3 points deducted, output 3.

Ideas:

For minimum buckle points, as far as possible because a relatively large fraction selected job before DDL do. Therefore, the job will be input by DDL descending score descending order, after the last start of the day to arrange a job, the DDL on the last day of work pressed into the priority queue, the decision by scores of size priority, if the queue is not empty, the maximum score that is the highest priority of the operational arrangements of the day, after the passage of the previous day, and the day's work DDL also pushed forward queue until you have arranged all day. Finally, still in the queue of jobs is the unfinished work, will add up their scores, that is to be deducted points.

Code:

#include <iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int size=1e6+5; 
struct ddl{
	int date;
	int score;
	bool operator<(const ddl&b)const
	{
		return score<b.score;
	}
};
ddl d[size];
bool cmp(ddl&a,ddl&b)
{
	return a.date!=b.date?a.date>b.date:a.score>b.score;
}
priority_queue<ddl>qq;
int main(int argc, char** argv) {
	int N;
	cin>>N;
	for(int ii=0;ii<N;ii++)
	{
		int n;
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>d[i].date;
		}
		for(int i=0;i<n;i++)
		{
			cin>>d[i].score;
		}
		sort(d,d+n,cmp);
		int last=d[0].date;
		int i=0;
		while(last>0)
		{
			for(;i<n&&d[i].date==last;i++) qq.push(d[i]);
			if(!qq.empty())
			{
				qq.pop();
			}
			last--;
		}
		int count=0;
		while(!qq.empty())
		{
			count+=qq.top().score;
			qq.pop();
		}
		cout<<count<<endl;
	}
	
	return 0;
}
Published 25 original articles · won praise 8 · views 535

Guess you like

Origin blog.csdn.net/weixin_44034698/article/details/104874140