传送门

 

1.贪心 + 优先队列

按照时间排序从前往后

很简单不多说

——代码

 1 #include <queue>
 2 #include <cstdio>
 3 #include <iostream>
 4 #include <algorithm>
 5 #define N 10001
 6 
 7 int n, t, ans;
 8 std::priority_queue <int, std::vector <int>, std::greater <int> > q;
 9 
10 struct node
11 {
12     int a, b;
13 }p[N];
14 
15 inline int read()
16 {
17     int x = 0, f = 1;
18     char ch = getchar();
19     for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
20     for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
21     return x * f;
22 }
23 
24 inline bool cmp(node x, node y)
25 {
26     return x.b < y.b;
27 }
28 
29 int main()
30 {
31     int i, j;
32     while(~scanf("%d", &n))
33     {
34         t = 1;
35         ans = 0;
36         while(!q.empty()) q.pop();
37         for(i = 1; i <= n; i++) p[i].a = read(), p[i].b = read();
38         std::sort(p + 1, p + n + 1, cmp);
39         for(i = 1; i <= n; i++)
40         {
41             if(t <= p[i].b)
42             {
43                 t++;
44                 ans += p[i].a;
45                 q.push(p[i].a);
46             }
47             else if(t == p[i].b + 1 && q.top() < p[i].a)
48             {
49                 ans += p[i].a - q.top();
50                 q.pop();
51                 q.push(p[i].a);
52             }
53         }
54         printf("%d\n", ans);
55     }
56     return 0;
57 }
View Code

相关文章:

  • 2021-06-22
  • 2022-12-23
  • 2021-09-07
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2021-09-24
猜你喜欢
  • 2021-09-22
  • 2021-11-28
  • 2021-09-29
  • 2022-02-24
  • 2021-10-08
  • 2022-12-23
  • 2021-05-28
相关资源
相似解决方案