Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions 한민주/20250330/P12015.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package algorithm;

// 메모리: 146912 KB, 시간: 564 ms
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gdgd


public class P12015 {
static ArrayList<Integer> list = new ArrayList<Integer>();
static int n;

static int find(int newVal) {
int s = 0;
int e = list.size() - 1;
if (list.isEmpty()||newVal > list.get(e) )
return -1;
while (s <= e) {
int mid = (s + e) / 2;
if (list.get(mid) == newVal) {
return mid;
} else if (list.get(mid) < newVal) {
s = mid + 1;
} else {
e = mid - 1;
}
}
return Math.max(s, e);
}

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());

for (int i = 0; i < n; i++) {
int newVal = Integer.parseInt(st.nextToken());
int idx = find(newVal);
if (idx == -1) {
list.add(newVal);
} else {
list.set(idx, newVal);
}
}

System.out.println(list.size());
}

}