Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[SW Expert Academy] 9280. 진용이네 주차 타워 본문

SW_Expert

[SW Expert Academy] 9280. 진용이네 주차 타워

코드와이 2021. 2. 3. 23:26

문제링크

swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AW9j74FacD0DFAUY&

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

package D3;

import java.util.ArrayList;
import java.util.Scanner;
 
 
public class 진용이네_주차타워 {
      
    public static void main(String[] args){
 
        Scanner sc = new Scanner(System.in);
         
        int T = sc.nextInt();
         
        for (int tc = 1; tc <= T; tc++) {
             
            int n = sc.nextInt();
            int m = sc.nextInt();
             
            int ans = 0;
             
            int[] r_i = new int[n];
            int[] w_i = new int[m];
             
            for (int i = 0 ; i < n ; i++) {
                r_i[i] = sc.nextInt();
            }
            for (int i = 0 ; i < m ; i++) {
                w_i[i] = sc.nextInt();
            }
             
            int[] park = new int[n];
            ArrayList<Integer> wait = new ArrayList<Integer>();
             
            for(int i = 0 ; i < 2*m; i++) {
                 
                int num = sc.nextInt();
                 
                if (num > 0) {
                    int j = 0;
                    for (j = 0 ; j < n; j++) {
                        if (park[j] == 0) {
                            park[j] = num;
                            ans += w_i[num-1] * r_i[j];
                            break;
                        }
                    }
                    if (j == n) {
                        wait.add(num);
                    }
                } else {
                    for (int j = 0 ; j < n; j++) {
                        if (park[j] == Math.abs(num)) {
                            if (wait.size() == 0) park[j] = 0;
                            else {
                                park[j] = wait.get(0);
                                ans += w_i[wait.get(0)-1] * r_i[j];
                                wait.remove(0);
                            }
                            break;
                        }
                    }
                }
            }
             
            System.out.println("#" + tc + " " + ans);
             
        }
    }       
}