#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long
int besthub(int R, int L, int X[], long long B) {
int ans=1;
ll cost=0;
int l=0,r=0;
for (int i=1; i<R; i++){
if (cost + (ll)(X[i] - X[0]) <= B){
ans++;
cost += (ll)(X[i] - X[0]);
r++;
}else break;
}
for (int i=1; i<R; i++){
ll dist=X[i] - X[i-1];
if (r<i){
r=i;
}else{
cost -= dist * (ll)(r-(i-1));
}
cost += dist * (ll)(i-l);
if (cost == B) {}
else if (cost < B){
while(1){
if (r+1 < R && cost + (ll)(X[r+1] - X[i]) <= B){
cost += (ll)(X[r+1] - X[i]);
r++;
}else break;
}
}else{ // cost > B
while(1){
if (cost <= B) break;
cost -= (ll)(X[i] - X[l]);
l++;
}
//try to expand
while(1){
if (r+1 < R && cost + (ll)(X[r+1] - X[i]) <= B){
cost += (ll)(X[r+1] - X[i]);
r++;
}else break;
}
}
ans=max(ans, r-l+1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
21 ms |
768 KB |
Output is correct |
4 |
Correct |
21 ms |
768 KB |
Output is correct |
5 |
Correct |
11 ms |
512 KB |
Output is correct |
6 |
Correct |
11 ms |
512 KB |
Output is correct |
7 |
Correct |
19 ms |
768 KB |
Output is correct |
8 |
Correct |
19 ms |
768 KB |
Output is correct |
9 |
Correct |
11 ms |
512 KB |
Output is correct |
10 |
Correct |
11 ms |
512 KB |
Output is correct |
11 |
Correct |
23 ms |
768 KB |
Output is correct |
12 |
Correct |
23 ms |
768 KB |
Output is correct |
13 |
Incorrect |
13 ms |
512 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |