#include "ricehub.h"
#include <bits/stdc++.h>
//#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 1e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
int n;
int besthub(int R, int L, int X[], long long B)
{
n = R;
if(n <= 5000)
{
int mx = 0;
for(int i=0; i<n; i++)
{
int l = i;
int r = i;
long long trsum = 0;
while(trsum <= B)
{
if(l == 0 && r!=n-1 && trsum + (X[r+1] - X[i]) <= B)
{
trsum += (X[++r] - X[i]);
}
else if(r == n-1 && l!=0 && trsum + (X[i] - X[l-1]) <= B)
{
trsum += (X[i] - X[--l]);
}
else if(l!=0 && r!=n-1 && (X[i] - X[l-1]) >= (X[r+1] - X[i]) && trsum+(X[r+1] - X[i])<=B)
{
trsum+=(X[++r] - X[i]);
}
else if(l!=0 && r!=n-1 && (X[i] - X[l-1]) <= (X[r+1] - X[i])&& trsum+(X[i] - X[l-1])<=B)
{
trsum+=(X[i] - X[--l]);
}
else break;
}
mx = max(mx, r-l+1);
}
return mx;
}
else
{
int l = 0;int r =1;
int i =0;
long long trsum = 0;
int cntr = 0;
int cntl =0;
int mx = 0;
while(r<n)
{
while(r<n)
{
if(trsum+ X[r] - X[i] <= B)
{
trsum+= X[r++] - X[i];
cntr++;
}
else if(l<i && X[r] - X[i] < X[i] - X[l] && trsum+ (X[r] - X[i]) - (X[i] - X[l]) <= B)
{
trsum -= (X[i] - X[l]);
trsum += (X[r] - X[i]);
l++;
r++;
}
else if(trsum > B && l<i)
{
cntl--;
trsum -= (X[i] - X[l++]);
}
else break;
}
mx = max(mx, r-l);
i++;
trsum += (i-l) *1ll * (X[i] - X[i-1]);
trsum -= (r-i) *1ll * (X[i] - X[i-1]);
}
return mx;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
448 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
444 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
29 ms |
348 KB |
Output is correct |
24 |
Correct |
27 ms |
348 KB |
Output is correct |
25 |
Correct |
76 ms |
348 KB |
Output is correct |
26 |
Correct |
80 ms |
348 KB |
Output is correct |
27 |
Correct |
27 ms |
348 KB |
Output is correct |
28 |
Correct |
20 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
452 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
8 ms |
1372 KB |
Output is correct |
4 |
Correct |
9 ms |
1568 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
860 KB |
Output is correct |
7 |
Correct |
7 ms |
1372 KB |
Output is correct |
8 |
Correct |
8 ms |
1372 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
4 ms |
856 KB |
Output is correct |
11 |
Correct |
9 ms |
1372 KB |
Output is correct |
12 |
Correct |
10 ms |
1568 KB |
Output is correct |
13 |
Correct |
5 ms |
856 KB |
Output is correct |
14 |
Correct |
4 ms |
968 KB |
Output is correct |
15 |
Correct |
6 ms |
1372 KB |
Output is correct |
16 |
Correct |
6 ms |
1372 KB |
Output is correct |
17 |
Correct |
7 ms |
1628 KB |
Output is correct |
18 |
Correct |
8 ms |
1628 KB |
Output is correct |
19 |
Correct |
8 ms |
1716 KB |
Output is correct |
20 |
Correct |
8 ms |
1592 KB |
Output is correct |