이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define rep(X, a,b) for(int X=a;X<b;++X)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (int)(a).size()
#define NL "\n"
using namespace std;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef long long ll;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const vector<A> &p){
for(const auto &a:p)
os << a << " ";
os << "\n";
return os;
}
ll n, m;
ll a[300010], b[300010];
int check(ll x){
ll left=0, need=0;
rep(i,0,n){
if(max(a[i], b[i])*m>=x) left+=(m-(ll)x/max(a[i], b[i])-(x%max(a[i], b[i])?1ll:0ll));
else need+=(ll)(x-(ll)max(a[i], b[i])*m)/b[i]+((x-(ll)max(a[i], b[i])*m)%b[i]?1ll:0ll);
}
return need<=left;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
rep(i,0,n) cin>>a[i];
rep(i,0,n) cin>>b[i];
ll l=0, r=1e18+1;
while(l<r-1){
ll mid=(l+r)>>1;
if(check(mid)) l=mid;
else r=mid;
}
cout<<l<<NL;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |