이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 << "\n";
}
# | 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... |