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;
struct dat
{
int price, len, id;
bool operator < (dat a) const{
return a.price > price;
}
};
int main()
{
int n, d;
cin>> n >> d;
vector<int> used(n, -1), price(n);
set<dat> best;
best.insert({-1, 0, -1});
multiset<int> el;
for(int i = 0; i < n; i++)
{
cin >> price[i];
if(i > d)
{
el.erase(el.find(price[i-d-1]));
while(best.size() > 1)
{
auto it = next(best.begin());
if(it->price < *el.begin()) best.erase(it);
else break;
}
}
auto it = best.lower_bound({price[i], -1, -1}), p = prev(it);
el.insert({price[i]});
if(it != best.end() && it->price == price[i]) continue;
if(it != best.end() && it->len == p->len+1) best.erase(it);
best.insert({price[i], p->len+1, i});
}
cout << prev(best.end())->len;
}
# | 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... |