标签:scan stream priority 没有 get 简单 不同类 empty mono
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2985 Accepted Submission(s): 984
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <queue> 6 #define N 100005 7 using namespace std; 8 struct Node { 9 int a, b; 10 } node[N]; 11 int m[N]; 12 int x, y; 13 bool cmp(Node x1, Node x2) { 14 return x1.a < x2.a; 15 } 16 priority_queue<int, vector<int>, greater<int> > q; 17 18 int main() { 19 20 while (scanf("%d%d", &x, &y) != EOF) { 21 while (!q.empty()) 22 q.pop(); 23 24 for (int i = 0; i < x; i++) 25 scanf("%d", &m[i]); 26 for (int i = 0; i < y; i++) 27 scanf("%d", &node[i].a); 28 for (int i = 0; i < y; i++) 29 scanf("%d", &node[i].b); 30 31 if (x > y) { 32 printf("No\n"); 33 continue; 34 } 35 sort(m, m + x); 36 sort(node, node + y, cmp); 37 int ans = y - 1; 38 long long int cnt = 0; 39 bool pi = true; 40 for (int i = x - 1; i >= 0; i--) { 41 while (ans >= 0 && node[ans].a >= m[i]) { 42 q.push(node[ans].b); 43 ans--; 44 } 45 if (q.empty()){ 46 pi = false; 47 break; 48 } 49 cnt += q.top(); 50 q.pop(); 51 } 52 if (pi) 53 printf("%lld\n", cnt); 54 else 55 printf("No\n"); 56 } 57 return 0; 58 }
标签:scan stream priority 没有 get 简单 不同类 empty mono
原文地址:http://www.cnblogs.com/zllwxm123/p/7241579.html