DDL fear

Topic 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.
Please help him!

Input:
Input of T test cases. 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.

Examples and tips:
Here Insert Picture Description

Problem-solving ideas: This is a greedy title, this time we maintain the largest fraction, using the maximum heap maintenance; then begin the enumeration from the last day of the deadline, when faced with deadlines, we put him (them) added to the maximum heap; and all day to come up with a score (the maximum heap, pulling out a maximum), and so on until the beginning of the day.
As can be seen from the enumeration we move forward after a few days and the maximum score is added to the heap, which prevents exceeding the deadline but will come out of it; this must be the best method here give ideas: from the back, add time t after selecting the same day and the best, at day t, we must take the pile of scores; if you do not take the largest in t days before got to come up (not out is not optimal ), if t come up with the biggest day of the current heap, the result was not bad; a chance to acquire a low-scoring high marks, and always get the highest, they difference is not significant (at a cut-off date of arrival before, we definitely have to get high points).

Code:

#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,int> > h;
bool cmp(pair<int,int> a,pair<int,int> b)
{
    return a.first>b.first;
}
int main()
{
    int n;
    cin>>n;
    while(n--)//多组输入
    {
        priority_queue<int> q;//最大堆
        int m,x;
        cin>>m;
        int total=0;
        int cnt=0;
        for(int i=0;i<m;i++)//h里面存的就是分数和日期
        {
            pair<int,int> u;
            cin>>x;
            u.first=x;
            h.push_back(u);
        }
        for(int i=0;i<m;i++)//这个是总分数
        {
            cin>>x;
            total+=x;
            h[i].second=x;
        }
        sort(h.begin(),h.end(),cmp);//排个序,按照截止日期
        int k=0;
        for(int i=h[0].first;i>=1;i--)//维护最大堆
        {
            if(i==h[k].first)
            {
                for(k;k<h.size();k++)
                {
                    if(h[k].first==i)
                    {
                        q.push(h[k].second);
                    }else
                    {
                        break;
                    }
                }
            }
            if(!q.empty())
            {
                cnt+=q.top();
                q.pop();
            }
        }
        cout<<total-cnt<<endl;//输出丢的分
        h.clear();
    }
}
Published 15 original articles · won praise 0 · Views 226

Guess you like

Origin blog.csdn.net/qq_43653717/article/details/104857738
DDL