#include "ricehub.h"
#include <cmath>
#include <vector>
#include <iostream>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
// cout << "Hello" << endl;
vector<long long> ac(R + 1);
ac[0] = 0;
for (int i = 1; i <= R; i++)
{
ac[i] = ac[i - 1] + (long long)X[i - 1];
}
long long min, max, med;
min = 1;
max = R;
// cout<<"Hello"<<endl;
while (true)
{
if (min == max or min > max)
{
return min;
}
med = ((min + max) / 2 )+1;
// cout<<med<<endl;
//hallamos la mitad de los posible y no posible
bool possible = false;
for (int i = 0; i <= R - med; i++)
{
long long izq = i;
long long der = i + med - 1;
long long mid = (izq + der) / 2;
long long aux = (mid - izq);
long long aux2 = (der - mid);
long long rm = X[mid];
long long sum = ((aux - aux2) * rm) - (ac[mid] - ac[izq]) + (ac[der + 1] - ac[mid + 1]);
if (sum <= B)
{
possible = true;
break;
}
}
if (possible == true)
{
min = med;
}
else
{
max = med - 1;
}
}
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
320 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
568 KB |
Output is correct |
3 |
Correct |
15 ms |
2508 KB |
Output is correct |
4 |
Correct |
19 ms |
2508 KB |
Output is correct |
5 |
Correct |
8 ms |
1228 KB |
Output is correct |
6 |
Correct |
8 ms |
1228 KB |
Output is correct |
7 |
Correct |
13 ms |
2252 KB |
Output is correct |
8 |
Correct |
13 ms |
2224 KB |
Output is correct |
9 |
Correct |
9 ms |
1120 KB |
Output is correct |
10 |
Correct |
7 ms |
1124 KB |
Output is correct |
11 |
Correct |
15 ms |
2516 KB |
Output is correct |
12 |
Correct |
15 ms |
2480 KB |
Output is correct |
13 |
Correct |
8 ms |
1228 KB |
Output is correct |
14 |
Correct |
10 ms |
1228 KB |
Output is correct |
15 |
Correct |
14 ms |
1968 KB |
Output is correct |
16 |
Correct |
11 ms |
1884 KB |
Output is correct |
17 |
Correct |
13 ms |
2252 KB |
Output is correct |
18 |
Correct |
18 ms |
2212 KB |
Output is correct |
19 |
Correct |
14 ms |
2356 KB |
Output is correct |
20 |
Correct |
14 ms |
2352 KB |
Output is correct |