#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
vector <ll> arr;
int besthub(int R, int L, int X[], ll B) {
//cerr << "Entrando a besthub..." << endl;
n = (ll)R;
// creamos el arreglo
for (ll i=0; i<n; i++) arr.push_back((ll)X[i]);
ll lb = 0, ub = 0, suma = 0LL, prev, maxi = 1LL;
//cerr << "Entrando al loop..." << endl;
for (ll i=0; i<n; i++) {
//cerr << "I = " << i << endl;
// 1. Actualizamos la suma
if (!i) {} // no toca si i == 0
else {
//cerr << "La suma paso de " << suma << " a ";
suma -= ((ub-(i-1))*(abs(prev-arr[i])));
suma += ((i-lb)*(abs(prev-arr[i])));
//cerr << suma << endl;
}
// 2. Recogemos lb
while (suma > B) {
suma -= abs(arr[lb]-arr[i]);
lb++;
}
// 3. Expandimos ub
while (ub+1 < n) {
if (suma + abs(arr[ub+1]-arr[i]) <= B) suma += abs(arr[ub+1]-arr[i]), ub++;
else break;
}
//cerr << "Nuevos valores, lb = " << lb << ", ub = " << ub << endl;
// 4. Contar
maxi = max(maxi, ub-lb+1);
prev = arr[i];
}
return maxi;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
17 ms |
1912 KB |
Output is correct |
4 |
Correct |
17 ms |
1912 KB |
Output is correct |
5 |
Correct |
8 ms |
1148 KB |
Output is correct |
6 |
Correct |
7 ms |
1148 KB |
Output is correct |
7 |
Correct |
15 ms |
1912 KB |
Output is correct |
8 |
Correct |
17 ms |
1912 KB |
Output is correct |
9 |
Correct |
7 ms |
1148 KB |
Output is correct |
10 |
Correct |
8 ms |
1148 KB |
Output is correct |
11 |
Correct |
20 ms |
1912 KB |
Output is correct |
12 |
Correct |
23 ms |
1912 KB |
Output is correct |
13 |
Incorrect |
9 ms |
1148 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |