#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
int besthub(int R, int L, int X[], ll B)
{
ll n = R;
ll T[n];
rep(i, n) {
T[i] = X[i];
}
ll ans = 0;
queue<ll> q;
ll ile1 = 0;
ll ile2 = 0;
ll poz = 0;
ll it = 0;
ll S = 0;
while (it < n && S + T[it] <= B) {
S += T[it];
q.push(T[it]);
ile2++;
it++;
}
ans = max(ans, ile1 + ile2);
rep(i, n) {
S -= (ile2 * (T[i] - poz));
S += (ile1 * (T[i] - poz));
ile1++;
ile2--;
poz = T[i];
// cout << "i = " << i << " poz = " << poz << endl;
// cout << "ile1 = " << ile1 << " ile2 = " << ile2 << endl;
// cout << "S = " << S << endl;
while (S > B) {
ll x = q.front();
q.pop();
S -= (T[i] - x);
ile1--;
}
while (true) {
// cout << "QQQQQQQ = " << q.front() << '\n';
if ((it >= n || S + (T[it] - poz) > B) && (it >= n || ((T[it] - poz) >= (poz - q.front())))) {
break;
}
if (S + (T[it] - poz) <= B) {
S += (T[it] - poz);
q.push(T[it]);
ile2++;
}
else {
S -= (poz - q.front());
q.pop();
S += (T[it] - poz);
q.push(T[it]);
ile2++;
ile1--;
}
it++;
}
ans = max(ans, ile1 + ile2);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
416 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
504 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
508 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
12 ms |
4176 KB |
Output is correct |
4 |
Correct |
11 ms |
4176 KB |
Output is correct |
5 |
Correct |
5 ms |
2896 KB |
Output is correct |
6 |
Correct |
5 ms |
2896 KB |
Output is correct |
7 |
Correct |
10 ms |
4176 KB |
Output is correct |
8 |
Correct |
10 ms |
4176 KB |
Output is correct |
9 |
Correct |
5 ms |
2896 KB |
Output is correct |
10 |
Correct |
6 ms |
2896 KB |
Output is correct |
11 |
Correct |
10 ms |
4176 KB |
Output is correct |
12 |
Correct |
12 ms |
4176 KB |
Output is correct |
13 |
Correct |
6 ms |
2896 KB |
Output is correct |
14 |
Correct |
6 ms |
2896 KB |
Output is correct |
15 |
Correct |
9 ms |
3664 KB |
Output is correct |
16 |
Correct |
9 ms |
3704 KB |
Output is correct |
17 |
Correct |
10 ms |
3920 KB |
Output is correct |
18 |
Correct |
11 ms |
3920 KB |
Output is correct |
19 |
Correct |
10 ms |
4344 KB |
Output is correct |
20 |
Correct |
12 ms |
4344 KB |
Output is correct |