이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
#define rep(a, b) for(int a = 0; a < (b); ++a)
const int LIM=3e5+7;
const ll INF=1e18+7;
ll A[LIM], B[LIM], n, m;
bool f(ll x) {
ll ile=0;
rep(i, n) {
ll p=(x+A[i]-1)/A[i];
p=min(p, m);
ll a=x-p*A[i];
ile+=p;
if(a>0) ile+=(a+B[i]-1)/B[i];
if(ile>n*m) return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
rep(i, n) cin >> A[i];
rep(i, n) {
cin >> B[i];
A[i]=max(A[i], B[i]);
}
ll p=0, k=INF;
while(p<k) {
ll sr=(p+k+1)/2;
if(f(sr)) p=sr; else k=sr-1;
}
cout << p << '\n';
}
# | 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... |