HDOJ-1789 Doing Homework again

来源:互联网 发布:手机照相摄像软件 编辑:程序博客网 时间:2024/05/16 02:41

先按分数对作业进行降序,在遍历每个作业,求出它可以完成的最迟时间,记下,若不能完成,则累加分数.

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <vector>#include <climits>#include <set>using namespace std;struct Work{    int day, score;    friend bool operator < (const Work &a, const Work &b)    {        return a.score > b.score;    }}work[1005];int main(){    //freopen("in.txt", "r", stdin);    int t;    cin >> t;    while(t--)    {        set<int> s;        int n, sum = 0;        cin >> n;        for(int i = 0; i < n; i++)            cin >> work[i].day;        for(int i = 0; i < n; i++)            cin >> work[i].score;        sort(work, work+n);        for(int i = 0; i < n; i++)        {            int j;            for(j = work[i].day; j >= 1; j--)            {                if(s.count(j) == 0)                {                    s.insert(j);                    break;                }            }            if(j == 0)            {                sum += work[i].score;            }        }        cout << sum << endl;    }    return 0;}
0 0
原创粉丝点击