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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = (ll)1e18 + 10;
int n, d, t;
vector<int> T;
struct ura
{
int pos, inc;
pll minn, seg;
};
pll faDP(ll lambda)
{
stack<ura> U;
pll seg;
U.push({-1, 0, {INF, -1}, {INF, -1}});
if (T[n - 1] > t)
{
U.push({n - 1, 0, {0, 0}, {0, 0}});
seg = {INF, 0};
}
else
seg = {1, 0};
for (int i = n - 2; i >= 0; i --)
{
pll m = min(seg, U.top().minn);
pll v = m;
v.first += lambda;
v.second ++;
seg = min(seg, v);
if (T[i] > t)
{
U.push({i, 0, m, seg});
seg = {INF, 0};
}
else
{
int diff = t - T[i];
seg.first ++;
U.top().inc ++;
U.top().minn.first ++;
U.top().seg.first ++;
while (U.size() > 1 && (U.top().pos - i) <= diff)
{
U.top().seg.first ++;
seg = min(seg, U.top().seg);
int inc = U.top().inc + 1;
U.pop();
U.top().inc += inc;
U.top().minn.first += inc;
U.top().seg.first += inc;
}
}
}
return min(seg, U.top().minn);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> d >> t;
T = vector<int>(n);
for(int i = 0; i < n; i ++)
cin >> T[i];
ll l = 0;
ll r = 4e6;
ll c, x;
while(l != r)
{
ll mid = (l + r) / 2;
x = faDP(mid).second;
if (x > d)
l = mid + 1;
else r = mid;
}
tie(c, x) = faDP(l);
cout << c - d * l << endl;
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |