This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "ricehub.h"
#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int R, L, X[MAXN];
ll B, dist[MAXN], pre[MAXN], sum[MAXN];
bool solve ( int x )
{
int mid;
ll total;
for ( int i = 1; i + x - 1 <= R; i++ )
{
mid = (i + (i + x - 1)) / 2;
total = ((mid - i) * pre[mid]) - (sum[mid - 1] - sum[i - 1]);
total += (sum[i + x - 1] - sum[mid]) - ((i + x - 1 - mid) * pre[mid]);
if ( total <= B )
return 1;
}
return 0;
}
int besthub ( int _r, int _l, int _x[], ll _b )
{
R = _r;
L = _l;
B = _b;
for ( int i = 1; i <= R; i++ )
X[i] = _x[i - 1];
X[0] = 0;
for ( int i = 1; i <= R; i++ )
dist[i] = X[i] - X[i - 1];
for ( int i = 1; i <= R; i++ )
pre[i] = pre[i - 1] + dist[i];
for ( int i = 1; i <= R; i++ )
sum[i] = sum[i - 1] + pre[i];
int s = 1, e = R, mid, val, ans;
while ( s <= e )
{
mid = (s + e) / 2;
val = solve ( mid );
if ( val )
ans = mid, s = mid + 1;
else
e = mid - 1;
}
return ans;
}
Compilation message (stderr)
ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:56:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
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... |