[BOJ] 2631 줄 세우기

Time Lapse :NONE

2631.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

#define MAXSIZE 1000

int n;
int num;
int ans = 0;
vector<int> temp;

int main(void)
{
cin >> n;
temp.push_back(-1);
for (int i = 0; i < n; i++)
{
cin >> num;
if (temp.back() < num)
{
temp.push_back(num);
ans++;
}
else
{
auto it = lower_bound(temp.begin(), temp.end(), num);
*it = num;
}
}
cout << n - ans << endl;

}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2631/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.