代码恢复训练 2024.6.13.
题目链接
解题思路
由于一个回合可以用所有无冷却的技能,因此我们对于技能肯定是能用就用的。
进而推出答案具有单调性。
直接二分答案即可,注意二分边界问题,这里我开了 __int128
来避免这个问题。
参考代码
点击查看代码
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define forll(i,a,b,c) for(register long long i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(register long long i=a;i>=b;i-=c)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid ((l+r)>>1)
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) (x&-x)
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
ll t;
ll n,m;
ll a[200010],b[200010];
ll L,R;
bool check(ll Mid)
{
__int128 sum=0;
forl(i,1,m)
{
sum+=(Mid/b[i]+1)*a[i];
if(sum>=n)
return 1;
}
return sum>=n;
}
void solve()
{
cin>>n>>m;
forl(i,1,m)
cin>>a[i];
forl(i,1,m)
cin>>b[i];
L=0,R=3e13;
while(L<R)
{
// cout<<L<<R<<endl;
ll Mid=(L+R)/2;
if(check(Mid))
R=Mid;
else
L=Mid+1;
}
cout<<L+1<<endl;
}
int main()
{
IOS;
t=1;
cin>>t;
while(t--)
solve();
QwQ;
}