이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 3*1e5;
int n, m, A[MAX_N], B[MAX_N], C[MAX_N];
bool check(int target){
//cout<<"target "<<target<<endl;
for(int i = 0; i<n; i++){
C[i] = A[i] * m;
}
int excess= 0;
for(int i = 0; i<n; i++){
if(C[i]>target){
excess += (C[i]-target)/A[i];
C[i]-= ((C[i]-target)/A[i])*A[i];
}
}
for(int i = 0; i<n; i++){
if(C[i]<target){
int need = (target-C[i]+B[i]-1)/B[i];
if(excess>=need){
excess-=need;
}
else{
return false;
}
}
}
return true;
}
signed main(){
cin>>n>>m;
for(int i = 0; i<n; i++){
cin>>A[i];
}
for(int i = 0; i<n; i++){
cin>>B[i];
A[i] = max(A[i], B[i]);
}
int res= 0LL;
for(int step = (1LL<<61LL); step>=1LL; step/=2LL){
//cout<<"hello "<<step<<endl;
if(check(res+step)){
res+=step;
}
}
cout<<res<<endl;
}
| # | 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... |