some dp problems
This commit is contained in:
26
CSES - CSES Problem Set/Sorting_And_Searching/Towers.cpp
Normal file
26
CSES - CSES Problem Set/Sorting_And_Searching/Towers.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by darian on 07.06.24.
|
||||
//
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
int n; cin >> n;
|
||||
vector<ll> towers;
|
||||
for (int i{}; i < n; i++) {
|
||||
ll a; cin >> a;
|
||||
auto it = std::lower_bound(towers.begin(), towers.end(), a+1);
|
||||
if (it == towers.begin()) {
|
||||
if (towers.size()) towers[0] = a;
|
||||
else towers.insert(towers.begin(), a);
|
||||
} else if (it == towers.end()) {
|
||||
towers.push_back(a);
|
||||
} else {
|
||||
towers[it - towers.begin()] = a;
|
||||
}
|
||||
}
|
||||
|
||||
cout << towers.size() << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user