Task
The idea was similar at the time of the competition. I felt that I could be able to handle it, and I had to handle it all. I still didn't think about it. Maybe it was a binary error -. -
N machines and M tasks to be completed. Each machine and task has two attributes. The machine is the maximum working time and level, A task is the time and level of work. You can get 500 * (Working Hours) + 2 * (levels) for completing a task. The task completion condition is that the machine's working time meets the task's needs. The level must be greater than or equal to the task level. One machine can only be used once, and one task can only be completed by one machine. You need to select policies to complete more tasks.
Idea: I started to think about greed. I also thought that time was the dominant factor when I was greedy. I had to give priority to it. When I wrote it after the game, I realized it using map.
1 struct node 2 { 3 int time, lev; 4 } a[100010], b[100010]; 5 6 int cmp(node a, node b) 7 { 8 if(a.time == b.time) 9 return a.lev > b.lev;10 return a.time > b.time;11 }12 13 map<int, int> M;14 int n, m;15 16 int main()17 {18 while(~scanf("%d%d", &n, &m))19 {20 for(int i = 0; i < n; ++i)21 {22 scanf("%d%d", &a[i].time, &a[i].lev);23 }24 for(int i = 0; i < m; ++i)25 {26 scanf("%d%d", &b[i].time, &b[i].lev);27 }28 sort(a, a+n, cmp);29 sort(b, b+m, cmp);30 M.clear();31 int j = 0;32 int ans1 = 0;33 long long ans2 = 0;34 for(int i = 0; i < m; ++i)35 {36 while(j < n && a[j].time >= b[i].time)37 {38 M[a[j].lev]++;39 ++j;40 }41 map<int, int>::iterator it = M.lower_bound(b[i].lev);42 if(it != M.end())43 {44 ans1++;45 ans2 += 500*b[i].time+2*b[i].lev;46 int t = it->first;47 M[t]--;48 if(M[t] == 0)49 {50 M.erase(t);51 }52 }53 }54 printf("%d %I64d\n", ans1, ans2);55 }56 57 return 0;58 }
HDU 4864