• 문제 링크
14754번: Pizza Boxes
Your program is to read from standard input. The input contains two integers, n and m (1 ≤ n, m ≤ 1,000), the number of rows and columns in the grid, respectively. Each of the following n lines contain m integers, the number of pizza boxes (heights) in
www.acmicpc.net
• 풀이 과정
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.stream.LongStream;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
long[] row = new long[n], col = new long[m];
long sum = 0;
for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < m; j++) {
int height = Integer.parseInt(st.nextToken());
sum += height;
row[i] = Math.max(row[i], height);
col[j] = Math.max(col[j], height);
}
}
sum -= LongStream.concat(Arrays.stream(row), Arrays.stream(col)).distinct().sum();
bw.write(String.valueOf(sum));
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 26215 눈 치우기 - Greedy / Java (0) | 2023.05.09 |
---|---|
[백준] 16206 롤케이크 - Greedy / Java (0) | 2023.05.08 |
[백준] 22864 피로도 - Greedy / Java (0) | 2023.05.06 |
[백준] 25644 최대 상승 - Greedy / Java (0) | 2023.05.05 |
[백준] 3022 PRASE - Data Structure / Java (0) | 2023.05.04 |
댓글