다름이아니라 제가 이번에 BOOKSTORE 문제를 푸는데 계속 시간초가라고 하네요... for문이 돌아가는 횟수를 줄여야 할것 같은데... 지금 계속 고민중인데 딱히 좋은 방법이 안떠올라서요 ㅠㅠ
조언좀 부탁드립니다~!
import java.util.*;
public class Main {
public static void main(String[] args) {
int t, total[], book[], price[], i=0, n, m, j, k=0, p=0;
Scanner sc = new Scanner(System.in);
t = sc.nextInt();
for(i=0; i<t; i++){
n = sc.nextInt();
m = sc.nextInt();
total = new int[m];
book = new int[n];
price = new int[m*n*2];
for(j=0; j<m*n*2; j+=2){
price[j] = sc.nextInt();
price[j+1] = sc.nextInt();
p = price[j]-price[j+1];
total[k] = total[k]+p;
if(k==m-1)
k=0;
else
k++;
}
Arrays.sort(total);
System.out.println(total[0]);
}
}
}
Sehee
안녕하세요? ALGOSPOT를 시작한지 아직 1주일이 안된 학생입니다 ㅎㅎ
다름이아니라 제가 이번에 BOOKSTORE 문제를 푸는데 계속 시간초가라고 하네요... for문이 돌아가는 횟수를 줄여야 할것 같은데... 지금 계속 고민중인데 딱히 좋은 방법이 안떠올라서요 ㅠㅠ
조언좀 부탁드립니다~!
14년 전