简单的贪心:
代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <cstdio> #include <set> #include <algorithm> #include <cstring> using namespace std; #define N 100005 struct st { int d,p; }num[N]; multiset<int> v; int fan(struct st A,struct st B) { if(A.p < B.p ||(A.p == B.p && A.d < B.d)) return 1; return 0; } int main() { int n,m; while(~scanf("%d %d",&n,&m)) { v.clear(); int x; for(int i = 0;i < n;i ++) { scanf("%d",&x); v.insert(x); } for(int i = 0;i < m;i ++) scanf("%d",&num[i].d); for(int i = 0;i < m;i ++) scanf("%d",&num[i].p); sort(num,num + m,fan); __int64 sum = 0; multiset<int>::iterator cp; for(int i = 0;i < m;i ++) { if(v.empty()) break; cp = v.upper_bound(num[i].d); if(cp == v.begin()) continue; else { cp --; sum += num[i].p; v.erase(cp); } } if(v.empty()) printf("%I64d\n",sum); else puts("No"); } return 0; }