๋ฌธ์ (์ถ์ฒ: https://www.acmicpc.net/problem/15282)
< Frosh Week >
๋ฌธ์ ํ์ด
์ฌ๋ ๊ฐ๊ฒฉ๊ณผ ์ ๋ฌด ์๊ฐ์ ๋ด๋ฆผ์ฐจ์์ผ๋ก ์ ๋ ฌํ๋ค. ์ฌ๋ ์๊ฐ ์์ ํด๊ฒฐํ ์ ์๋ ์ ๋ฌด ๊ฐ์๋ฅผ ๊ตฌํ๋ค.
my solution (Java)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class _15282_ { // Frosh Week
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
Integer task[] = new Integer[n];
Integer interval[] = new Integer[m];
st = new StringTokenizer(bf.readLine());
for (int i = 0; i < n; i++) {
task[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(bf.readLine());
for (int i = 0; i < m; i++) {
interval[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(task, Collections.reverseOrder());
Arrays.sort(interval, Collections.reverseOrder());
int idx = 0, idx2 = 0, result = 0;
while (idx < m && idx2 < n) {
if (interval[idx] >= task[idx2]) {
result += 1;
idx += 1;
}
idx2 += 1;
}
System.out.println(result);
}
}
๋ณ์)
n, m : ์ ๋ฌด ๊ฐ์, ์ฌ๋ ์๊ฐ ๊ฐ์
task, interval : ์ ๋ฌด ์๊ฐ, ์ฌ๋ ์๊ฐ
idx, idx2 : ๊ฐ ์ธ๋ฑ์ค
result : ์ํํ ์ ์๋ ์ ๋ฌด ๊ฐ์
์ ๋ฌด ๊ฐ์์ ์ฌ๋ ์๊ฐ ๊ฐ์๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค. ๊ฐ ๊ฐ์๋งํผ ์๊ฐ์ ์ ๋ ฅ๋ฐ์ task, interval ๋ฐฐ์ด์ ์ ์ฅํ๋ค. ๊ฐ ๋ฐฐ์ด์ ๋ด๋ฆผ์ฐจ์์ผ๋ก ์ ๋ ฌํ๋ค. ์ฌ๋ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก ์ ๋ฌด๋ฅผ ์ํํ ์ ์๋์ง ์๋์ง ํ์ธํ๋ค. ์ฌ๋ ์๊ฐ์ ์ ๋ฌด๋ฅผ ์ํํ ์ ์์ผ๋ฉด ๊ฐ ์ธ๋ฑ์ค๋ฅผ 1 ๋ํ๊ณ result๋ 1 ๋ํ๋ค. ์ ๋ฌด๋ฅผ ์ํํ ์ ์๋ค๋ฉด ์ ๋ฌด ์ธ๋ฑ์ค๋ฅผ 1 ๋ํ๋ค.
์ต์ข result๋ฅผ ์ถ๋ ฅํ๋ค.
'๐Algorithm > ๐ฅBaekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 13281_Look for the Winner! (0) | 2024.12.23 |
---|---|
[Baekjoon] 21208_Gratitude (1) | 2024.12.20 |
[Baekjoon] 5078_Shirts (0) | 2024.12.18 |
[Baekjoon] 6108_The Perfect Cow (0) | 2024.12.17 |
[Baekjoon] 13211_Passport Checking (0) | 2024.12.13 |