답안 #113162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113162 2019-05-24T03:47:31 Z joseacaz Garage (IOI09_garage) C++17
100 / 100
6 ms 384 KB
#include <iostream>
#include <queue>
#define MAXN 105
#define MAXM 2005

using namespace std;
typedef long long lld;

int N, M, cost[MAXN], weight[MAXM], car, space[MAXM], aux, ans;
queue < int > Q;
priority_queue < int > PQ;

int main ()
{
	cin >> N >> M;
	for ( int i = 1; i <= N; i++ )
		cin >> cost[i];
	for ( int i = 1; i <= M; i++ )
		cin >> weight[i];
	
	for ( int i = 1; i <= N; i++ )
		PQ.push(-i);
	
	for ( int i = 0; i < 2 * M; i++ )
	{
		cin >> car;
		if ( car < 0 )
		{
			car = -car;
			
			if ( Q.size () > 0 )
			{
				aux = space[car];

				space[Q.front()] = aux;
				ans += (cost[aux] * weight[Q.front()] );

				Q.pop();
			}
			else
			{
				PQ.push ( -space[car] );
				space[car] = 0;
			}
		}
		else if ( car > 0 )
		{
			if ( PQ.size() > 0 )
			{
				aux = -PQ.top();
				PQ.pop();

				space[car] = aux;
				ans += (cost[aux] * weight[car]);
			}
			else
				Q.push ( car );
		}
	}
	
	cout << ans << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct