题解
令 \(f(x)\) 代表所有课的发布时间都小于等于x时的不愉快值之和,x越小,AB消耗越大,x越大,C消耗越大,所以感性的想象 \(f(x)\) 是一个下凹函数
然后就可以快乐三分了
code
#define ll unsigned long long
#include<bits/stdc++.h>
using namespace std;
inline void read(ll &x) {
x = 0;
ll flag = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-')flag = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
x *= flag;
}
inline void write(ll x)
{
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
ll t[100005];
ll b[100005];
ll A,B,C;
ll n,m;
ll f(ll x)
{
ll sum=0;
for(ll i=1;i<=n;i++) if(t[i]<x) sum+=C*(x-t[i]);
if(A>B)
{
for(ll i=1;i<=m;i++) if(b[i]>x) sum+=B*(b[i]-x);
}
else
{
ll extra=0,need=0;
for(ll i=1;i<=m;i++)
{
if(b[i]>x) need+=b[i]-x;//这里对AB的处理太巧妙了,学着点
else if(b[i]<x) extra+=x-b[i];
}
if(need<=extra) sum+=A*need;
else sum+=A*extra+B*(need-extra);
}
return sum;
}
int main()
{
read(A); read(B); read(C);
read(n); read(m);
for(ll i=1;i<=n;i++) read(t[i]);
for(ll i=1;i<=m;i++) read(b[i]);
ll l=1,r=100000;
while(l+10<=r)
{
ll midl=l+(r-l)/3;
ll midr=r-(r-l)/3;
if(f(midl)>f(midr)) l=midl;
else r=midr;
}
ll ans=1e19;
for(ll i=l;i<=r;i++) ans=min(ans,f(i));
write(ans); putchar('\n');
return 0;
}
标签:ix,六省,ll,long,联考,P3745,else,2017
From: https://www.cnblogs.com/pure4knowledge/p/18120978