标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1705 Accepted Submission(s): 567
1 #include<iostream> 2 #include<queue> 3 #include<algorithm> 4 #include<cstdio> 5 #define MAXN 100010 6 using namespace std; 7 int rabbit[MAXN]; 8 struct Narrow 9 { 10 int d,p; 11 }narrow[MAXN]; 12 bool cmp1(Narrow a,Narrow b) 13 { 14 return a.d<b.d; 15 } 16 struct cmp 17 { 18 bool operator()(int x,int y) 19 { 20 return x>y; 21 } 22 }; 23 priority_queue<int,vector<int>,cmp>q; 24 int n,m; 25 int main() 26 { 27 while(scanf("%d%d",&n,&m)==2) 28 { 29 for(int i=0;i<n;i++) 30 scanf("%d",&rabbit[i]); 31 for(int i=0;i<m;i++) 32 scanf("%d",&narrow[i].d); 33 for(int i=0;i<m;i++) 34 scanf("%d",&narrow[i].p); 35 if(n>m) 36 { 37 printf("No\n"); 38 continue; 39 } 40 sort(rabbit,rabbit+n); 41 sort(narrow,narrow+m,cmp1); 42 while(!q.empty()) 43 q.pop(); 44 int temp=m-1; 45 bool flag=true; 46 long long int ans=0; 47 for(int i=n-1;i>=0;i--) 48 { 49 while(narrow[temp].d>=rabbit[i]) 50 { 51 q.push(narrow[temp].p); 52 temp--; 53 } 54 if(q.empty()) 55 { 56 flag=false; 57 break; 58 } 59 ans+=q.top(); 60 q.pop(); 61 } 62 if(flag)cout<<ans<<endl; 63 else printf("No\n"); 64 } 65 return 0; 66 }
标签:
原文地址:http://www.cnblogs.com/lthb/p/4391134.html