做法:二分
思路:
考虑每次充最小使用时间的电脑(即)
判断是否符合作为二分条件
代码
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;
const double PI=acos(-1.0);
int n,k;
ll a[N],b[N],ans=-1;
struct node{
ll a,b,c;
bool operator <(const node &t)const{
if(c!=t.c)return c>t.c;
if(b!=t.b)return b<t.b;
return a>t.a;
}
};
bool check(ll mid){
priority_queue<node> q;
_for(i,n){
if(a[i]/b[i]<k) q.push({a[i],b[i],a[i]/b[i]});
}
if(q.empty()) return true;
_for(i,k){
auto t=q.top();q.pop();
if(t.c<i) return false;
if((t.a+mid)/t.b<k) q.push({t.a+mid,t.b,(t.a+mid)/t.b});
if(q.empty()) return true;
}
return true;
}
void solve(){
cin>>n>>k;
_for(i,n) cin>>a[i];
_for(i,n) cin>>b[i];
ll l=0,r=2e12;
while(l<=r){
ll mid=(l+r)>>1;
if(check(mid)){
ans=mid;
r=mid-1;
}
else l=mid+1;
}
printf("%lld\n",ans);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef DEBUG
freopen("F:/laji/1.in", "r", stdin);
// freopen("F:/laji/2.out", "w", stdout);
#endif
// int t;cin>>t;while(t--)
solve();
return 0;
}
京公网安备 11010502036488号