#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
// # define int long long
int besthub(int n, int mx, int a[], long long b)
{
int ans = 1;
for ( int i = 0; i < n; i++ ) {
int x = a[i];
vector < int > vc;
vc.push_back( 0 );
for ( int j = i - 1; j >= 0; j-- ) {
vc.push_back( vc.back() + (x - a[j]) );
}
// cout << x << '\n';
// for ( auto j: vc ) {
// cout << j << ' ';
// }
// cout << "\n";
long long pr = 0;
for ( int j = i + 1; j < n; j++ ) {
pr += a[j] - x;
int left = b - pr;
// cout << a[j] << ' ' << left << '\n';
if ( left < 0 ) {
continue;
}
ans = max( ans, j - i + 1 );
auto it = upper_bound( vc.begin(), vc.end(), left );
// it--;
if ( it != vc.begin() ) {
it--;
}
int ind = it - vc.begin();
// cout << a[j] << ' ' << pr << ' ' << ind << '\n';
ans = max( ans, j - i + ind + 1 );
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
256 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
6 ms |
384 KB |
Output is correct |
23 |
Correct |
7 ms |
384 KB |
Output is correct |
24 |
Correct |
7 ms |
384 KB |
Output is correct |
25 |
Correct |
7 ms |
256 KB |
Output is correct |
26 |
Correct |
8 ms |
384 KB |
Output is correct |
27 |
Correct |
7 ms |
384 KB |
Output is correct |
28 |
Correct |
7 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
12 ms |
384 KB |
Output is correct |
4 |
Correct |
14 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
256 KB |
Output is correct |
7 |
Correct |
10 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
384 KB |
Output is correct |
9 |
Correct |
6 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
11 |
Correct |
8 ms |
384 KB |
Output is correct |
12 |
Correct |
9 ms |
384 KB |
Output is correct |
13 |
Correct |
14 ms |
384 KB |
Output is correct |
14 |
Correct |
16 ms |
384 KB |
Output is correct |
15 |
Correct |
7 ms |
384 KB |
Output is correct |
16 |
Correct |
8 ms |
256 KB |
Output is correct |
17 |
Correct |
11 ms |
384 KB |
Output is correct |
18 |
Correct |
12 ms |
384 KB |
Output is correct |
19 |
Correct |
14 ms |
384 KB |
Output is correct |
20 |
Correct |
21 ms |
384 KB |
Output is correct |
21 |
Correct |
116 ms |
384 KB |
Output is correct |
22 |
Correct |
114 ms |
384 KB |
Output is correct |
23 |
Correct |
261 ms |
504 KB |
Output is correct |
24 |
Correct |
333 ms |
504 KB |
Output is correct |
25 |
Correct |
312 ms |
636 KB |
Output is correct |
26 |
Correct |
336 ms |
384 KB |
Output is correct |
27 |
Correct |
292 ms |
384 KB |
Output is correct |
28 |
Correct |
305 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |