소프티어 lv.3 Hanyang Popularity Exceeding Competition

알고리즘/java 2025. 4. 15. 22:17
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		int result = 0;
		
		for (int i = 0; i < n; i++) {
			if(incresedPopular(br.readLine().split(" "), result)) result++;
		}
		
		System.out.println(result);
		
	}
	
	public static boolean incresedPopular(String[] arr, int popularity) {
		return Math.abs(Integer.parseInt(arr[0]) - popularity) <= Integer.parseInt(arr[1]);
	}
}

 

https://softeer.ai/practice/9495

 

만나는 사람의 순서는 바뀌지 않으므로

철민이의 현재 인기도와 유명인의 인기도의 차이의 절대값과 친화력을 비교해서
철민이의 인기도를 1씩 증가시켜나가면 된다.