This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |