#include <bits/stdc++.h>
#define ll long long
#include "ricehub.h"
//#include "grader.cpp"
using namespace std;
queue<int> qL, qR;
int besthub(int R, int L, int X[], ll B) {
ll cost = 0, cur = 1;
int ans = 0;
for (int i = 0; i < R; ++i) {
if (i != 0) cost += (X[i]-X[i-1])*qL.size();
if (i != 0) cost -= (X[i]-X[i-1])*qR.size();
if (!qR.empty() && qR.front() == X[i]) qR.pop();
if (cur <= i) cur++;
qL.push(X[i]);
while (cost > B) {
cost -= X[i]-qL.front();
qL.pop();
}
while (cur < R) {
if (cost + X[cur] - X[i] > B) {
if (cost - (X[i]-qL.front()) + (X[cur]-X[i]) <= cost) {
cost -= X[i]-qL.front();
cost += X[cur]-X[i];
qL.pop();
qR.push(X[cur++]);
}
else break;
}
else {
cost += X[cur] - X[i];
qR.push(X[cur++]);
}
}
int cur = qL.size() + qR.size();
ans = max(ans, cur);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
220 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
480 KB |
Output is correct |
3 |
Correct |
17 ms |
2180 KB |
Output is correct |
4 |
Correct |
12 ms |
2124 KB |
Output is correct |
5 |
Correct |
6 ms |
836 KB |
Output is correct |
6 |
Correct |
6 ms |
852 KB |
Output is correct |
7 |
Correct |
11 ms |
1888 KB |
Output is correct |
8 |
Correct |
10 ms |
1792 KB |
Output is correct |
9 |
Correct |
5 ms |
808 KB |
Output is correct |
10 |
Correct |
5 ms |
808 KB |
Output is correct |
11 |
Correct |
13 ms |
2124 KB |
Output is correct |
12 |
Correct |
14 ms |
2132 KB |
Output is correct |
13 |
Correct |
6 ms |
868 KB |
Output is correct |
14 |
Correct |
6 ms |
816 KB |
Output is correct |
15 |
Correct |
9 ms |
1708 KB |
Output is correct |
16 |
Correct |
9 ms |
1572 KB |
Output is correct |
17 |
Correct |
11 ms |
1964 KB |
Output is correct |
18 |
Correct |
14 ms |
1976 KB |
Output is correct |
19 |
Correct |
12 ms |
2004 KB |
Output is correct |
20 |
Correct |
12 ms |
2064 KB |
Output is correct |