제출 #1092522

#제출 시각아이디문제언어결과실행 시간메모리
1092522hungntFinancial Report (JOI21_financial)C++14
100 / 100
265 ms37204 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...