모든 적립금에서 가장 적은 적립금을 뺀다. (마지막으로 산 책에 대한 적립금은 사용하지 못하므로, 적립금이 가장 적은 책을 마지막에 산다.)
total price 에서 2번에서 계산된 적립금을 뺀다.
이런 생각으로 문제를 풀었는데 잘못된 생각인가요?
예제에 대해서는 정상작동하는데 오답이 뜨네요. 무엇이 문제일까요..
아래는 소스 코드입니다.
import java.util.Scanner;
class Book {
public int price;
public int point;
public Book(int price, int point) {
this.price = price;
this.point = point;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int cases = scanner.nextInt();
while( cases-- > 0 ) {
// Do Something
int N = scanner.nextInt(); // The number of books
int M = scanner.nextInt(); // The number of stores
Book books[][] = new Book[N][M];
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
int price = scanner.nextInt();
int point = scanner.nextInt();
books[i][j] = new Book(price, point);
}
}
int min = Integer.MAX_VALUE;
for(int i=0; i<M; i++) {
int total_price = 0;
int total_point = 0;
int min_point = Integer.MAX_VALUE;
for(int j=0; j<N; j++) {
total_price += books[j][i].price;
total_point += books[j][i].point;
if(min_point > books[j][i].point) min_point = books[j][i].point;
}
total_point -= min_point;
if(min > (total_price - total_point) ) min = (total_price - total_point);
}
System.out.println(min);
}
}
}
gnoowik
[[problem:BOOKSTORE]]
이런 생각으로 문제를 풀었는데 잘못된 생각인가요?
예제에 대해서는 정상작동하는데 오답이 뜨네요. 무엇이 문제일까요..
아래는 소스 코드입니다.
11년 전