이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
// int ans;
int n = R;
long long int lsum,rsum;
deque<int> le,re;
int f = 1, b = n,ans=1;
while(f <= b){
//cout << f << " " << b << "\n";
int mid = ((f+b) >> 1);
lsum = rsum = 0;
le.clear();
re.clear();
for (int i = 0; i < (mid+1)/2; i++){
lsum += X[i];
le.push_back(X[i]);
}
for (int i = (mid+1)/2; i < mid; i++){
rsum += X[i];
re.push_back(X[i]);
}
// cout << mid << " " << lsum << " " << rsum << "\n";
/*if (mid%2==1){
int nxt = re.front();
re.pop_front();
rsum -= nxt;
lsum += nxt;
}*/
bool pos = false;
if (rsum - lsum < B){
ans = mid;
f = mid+1;
// cout << "f ";
continue;
}
int nxt,temp1,temp2,itr = mid;
while(itr < n){
nxt = X[itr];
temp1 = re.front();
temp2 = le.front();
rsum += (nxt-temp1);
lsum += (temp1-temp2);
re.pop_front();
le.pop_front();
re.push_back(nxt);
le.push_back(temp1);
// cout << mid << " " << lsum << " " << rsum << "\n";
if (rsum - lsum <= B){
pos = true;
break;
}
itr++;
}
if (pos){
ans = mid;
f = mid+1;
// cout << "f ";
}
else {
b = mid-1;
// cout << "b ";
}
// cout << "\n";
}
return ans;
}
# | 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... |