Submission #113162

#TimeUsernameProblemLanguageResultExecution timeMemory
113162joseacazGarage (IOI09_garage)C++17
100 / 100
6 ms384 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...