记录编号 586744 评测结果 AAAAAAAAAAAAAAAAAAAAA
题目名称 最近的母牛获胜 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 1.823 s
提交时间 2024-02-27 19:59:54 内存使用 16.64 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5+10;
int n,m,k;
ll sum,ans;
struct made{
    int p;ll t;
}a[N];
int f[N];
bool cmp(made x,made y){
    return x.p < y.p;
}
priority_queue<int,vector<int>,less<int> >q;
void work(){
    int i = 1;
    while(i <= n && a[i].p < f[1])sum += a[i++].t;
    q.push(sum);
    for(int j = 2;j <= m;j++){
        sum = 0;int u = i;
        while(u <= n && a[u].p < f[j])sum += a[u++].t;
        int mid = (f[j] - f[j-1]) / 2;
        ll s = 0,l = i,r = i,mx = 0;
        while(r < u){
            while(l < r && a[r].p - a[l].p >= mid)s -= a[l].t,l++;
            s += a[r++].t;
            mx = max(mx,s);
        }
        q.push(mx),q.push(sum-mx); 
        i = u;
    }
    sum = 0;
    while(i <= n)sum += a[i++].t;
    q.push(sum);
}
int main(){
    freopen("Closest_Cow_Wins.in","r",stdin);
    freopen("Closest_Cow_Wins.out","w",stdout);
    scanf("%d%d%d",&n,&m,&k);
    for(int i = 1;i <= n;i++)scanf("%d%lld",&a[i].p,&a[i].t);
    for(int i = 1;i <= m;i++)scanf("%d",&f[i]);
    sort(a+1,a+1+n,cmp);
    sort(f+1,f+1+m);
    work();
    while(k-- && !q.empty())ans += q.top(),q.pop();
    printf("%lld\n",ans);

	return 0;

}