728x90

import java.util.ArrayDeque;
import java.util.Scanner;
class Solution {
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 rate[] = new int[n];
int weight[] = new int[m];
int parkP[] = new int[m]; // 어디에 댔는지
boolean isPark[] = new boolean[n]; // 주차 공간이 찼는지
ArrayDeque<Integer> q = new ArrayDeque<>(); // 대기 큐
int size = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
rate[i] = sc.nextInt();
}
for (int i = 0; i < m; i++) {
weight[i] = sc.nextInt();
}
for (int i = 0; i < 2 * m; i++) {
int car = sc.nextInt();
if (car > 0) {
if (size < n) {
for (int j = 0; j < n; j++) {
if (!isPark[j]) {
isPark[j] = true;
parkP[car - 1] = j;
size++;
break;
}
}
} else {
q.offer(car);
}
} else {
car = Math.abs(car) - 1;
sum += rate[parkP[car]] * weight[car];
isPark[parkP[car]] = false;
size--;
if (!q.isEmpty()) {
for (int j = 0; j < n; j++) {
if (!isPark[j]) {
isPark[j] = true;
parkP[q.poll() - 1] = j;
size++;
}
}
}
}
}
System.out.println("#" + tc + " " + sum);
}
}
}728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 숫자가 같은 배수 (D3) (0) | 2024.10.01 |
|---|---|
| [SW Expert Academy] 알 덴테 스파게티 (D3) (9) | 2024.10.01 |
| [SW Expert Academy] 조 만들기 (D3) (0) | 2024.10.01 |
| [SW Expert Academy] 파도반 수열 (D3) (0) | 2024.09.29 |
| [SW Expert Academy] 정삼각형 분할 놀이 (D3) (0) | 2024.09.29 |