이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long a[300005], b[300005];
long long l, r, mid;
bool check(long long x) {
long long extra = 0, need = 0;
for(int i=1; i<=n; i++) {
if(a[i] > b[i]){ // study in class
long long needed = (x + a[i] - 1) / a[i];
if(needed > m) {
need += (x - a[i] * m + b[i] - 1) / b[i];
if(need > 1e18) return false;
} else {
extra += m - needed;
}
} else { // study at any time
extra += m;
need += (x + b[i] - 1) / b[i];
if(need > 1e18) return false;
}
}
if(extra>=need) return true;
else return false;
}
int main() {
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=n; i++) cin >> b[i];
l = 0; r = 1e18;
while(l<r) {
mid = (l+r+1)/2;
if(check(mid)) l = mid;
else r = mid - 1;
}
cout << l << "\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... |