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;
using ll = long long;
typedef pair<int, int> pii;
int besthub(int n, int L, int X[], long long b)
{
vector <ll> fields;
for (int i = 0; i < n; i++) fields.emplace_back(X[i]);
auto pos = fields.begin(), lt = fields.begin(), rt = fields.begin() + 1;
ll cur = 0;
if (n == 1) return 1;
long output = 0;
while (rt != fields.end())
{
while (cur > b)
{
cur -= *pos - *lt;
lt++;
}
while (rt != fields.end() && cur + (*rt - *pos) <= b)
{
cur += (*rt - *pos);
rt++;
}
while (rt != fields.end() && (*pos - *lt) > (*rt - *pos))
{
cur += (*rt - *pos) - (*pos - *lt);
lt++, rt++;
while (rt != fields.end() && cur + (*rt - *pos) <= b)
{
cur += (*rt - *pos);
rt++;
}
}
// cout << lt - fields.begin() << " " << pos - fields.begin() << " " << rt - fields.begin() << "\n";
output = max(output, ((rt - fields.begin()) - (lt - fields.begin())));
pos++;
if (rt != fields.end())
{
// cout << "c";
// cout << cur << " ";
cur += (*pos - *(pos - 1)) * ((pos - fields.begin()) - (lt - fields.begin()));
// cout << cur << " ";
cur += (*(pos - 1) - *pos) * ((rt - fields.begin()) - (pos - fields.begin()));
// cout << cur << "\n";
}
}
// cerr << output << "\n";
return output;
}
# | 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... |