이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n;
int r1;
int a[N];
long long p[N];
long long s;
int f( int x )
{
int l = 1 , r = n;
while( l < r ){
int m = (l + r) / 2;
if( a[m + 1] > x )r = m;
else l = m + 1;
}
int res = 1;
long long y = 0;
for( int i = l + 1 , j = l; i <= n; i++ ){
y += 1ll * a[i] - x;
l = 1 , r = j;
long long cnt = 0;
while( l < r ){
int m = (l + r) / 2;
if( 1ll * x * (j - m + 1) - (p[j] - p[m - 1]) + y > s )l = m + 1;
else r = m;
}
if( 1ll * x * (j - l + 1) - (p[j] - p[l - 1]) + y <= s )res = max( i - l + 1 , res );
if( y <= s )res = max( res , i - j );
}
return res;
}
int besthub(int R, int L, int X[], long long B)
{
n = R;
r1 = L;
for( int i = 1; i <= n; i++ )a[i] = X[i - 1];
for( int i = 1; i <= n; i++ ){
p[i] = p[i - 1];
p[i] += a[i];
}
s = B;
int l = 1 , r = r1;
while( r - l >= 1000 ){
int m1 = l + (r - l) / 3;
int m2 = r - (r - l) / 3;
if( f(m1) < f(m2) )l = m1;
else r = m2;
}
int ans = f(l);
for( int i = l + 1; i <= r; i++ ){
ans = max( ans , f(i) );
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
ricehub.cpp: In function 'int f(int)':
ricehub.cpp:27:19: warning: unused variable 'cnt' [-Wunused-variable]
long long cnt = 0;
^~~
# | 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... |