슈콩

[SWEA] 진용이네 주차타워 본문

Algorithms/SWEA

[SWEA] 진용이네 주차타워

shukong 2025. 11. 12. 18:37

 

 

[문제]

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

 

SW Expert Academy

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

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());
			int[] cost = new int[n+1];
			for(int i=1;i<=n;i++) {
				cost[i] = Integer.parseInt(br.readLine());
			}
			int[] weight = new int[m+1];
			for(int i=1;i<=m;i++) {
				weight[i] = Integer.parseInt(br.readLine());
			}
			boolean[] canP = new boolean[n+1];
			int[] parking = new int[m+1];
			Queue<Integer> q = new LinkedList<>();
			int result = 0;
			for(int i=0;i<m*2;i++) {
				int curr = Integer.parseInt(br.readLine());
				if(curr>0) {
					boolean check = false;
					for(int j=1;j<=n;j++) {
						if(!canP[j]) {
							canP[j] = true;
							parking[curr] = j;
							check = true;
							break;
						}
					}
					if(!check)
						q.offer(curr);
				}
				else {
					curr *= -1;
					canP[parking[curr]] = false;
					result += weight[curr] * cost[parking[curr]];
					if(!q.isEmpty()){
						canP[parking[curr]] = true;
						parking[q.poll()] = parking[curr];
					}
				}
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 민석이의 과제 체크하기  (0) 2025.11.12
[SWEA] 현주의 상자 바꾸기  (3) 2025.11.12
[SWEA] 원 안의 점  (0) 2025.11.12
[SWEA] 최장 증가 부분 수열  (0) 2025.11.12
[SWEA] 8일차 - 암호문3  (0) 2025.11.12