| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 39162 | LYLAKIOI | 【S】T3 | C++ | 通过 | 100 | 644 MS | 8940 KB | 1872 | 2025-12-23 08:33:47 |
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } const int maxn=1e6+10,mod=1e9+7; int n,k,a[maxn],b[maxn]; namespace greedy{ ll a[maxn];int i,c;ll res; priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >q1,q2; void init(int lim){ up(i,1,n)a[i]=::a[i]-lim;c=res=0; while(!q1.empty())q1.pop();while(!q2.empty())q2.pop(); } ll f0(int o){if(o)q1.push({a[i],i});return 0;} ll f1(int o){if(o)q2.push({-b[i],i}),c++;return a[i]+b[i];} ll f2(int o){if(q2.empty())return 1e18;int j=q2.top().p2;if(o)q2.pop(),q2.push({-b[i],i}),q1.push({a[i],i});return b[i]-b[j];} ll f3(int o){if(q1.empty())return 1e18;int j=q1.top().p2;if(o)q1.pop(),q2.push({-b[i],i}),q1.push({a[i],i}),c++;return b[i]+a[j];} function<ll(int)>F[4]={f1,f3,f0,f2}; int qr(int lim){ init(lim); for(i=1;i<=n;i++){ int p=0;up(j,1,3)if(F[j](0)<F[p](0))p=j; res+=F[p](1); } return c; } } using greedy::qr; using greedy::res; void slv(){ n=read(),k=read(); if(k>n)return cout<<(ll)(1e18),void(); up(i,1,n)a[i]=read(); up(i,1,n)b[i]=read(); ll L=-2e9,R=2e9; while(L+1<R){ ll mid=L+R>>1; if(qr(mid)>=k)R=mid; else L=mid; } qr(R);cout<<res+R*k; } int main(){ //freopen("1.in","r",stdin),freopen("1.out","w",stdout); slv(); return 0; }