[BOJ] 1377 버블 소트

Time Lapse :None

1377.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
39
40
41
42
43
44
45
46
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

#define MAXSIZE 500001

struct point {
int num;
int index;
point(int a, int b) : num(a), index(b) {}
};
int n;
vector <point> arr;
int ans = 0;
int num;

bool compare(const point& p1, const point& p2)
{
if (p1.num == p2.num)
return p1.index < p2.index;
return p1.num < p2.num;
}


int main(void)
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> num;
point P(num, i);
arr.push_back(P);
}
sort(arr.begin(), arr.end(),compare);
for (int i = 0; i < n; i++)
{
ans = max(ans,arr[i].index-i);
}
cout << ans+1 << endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/1377/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.