Submission #1016142

#TimeUsernameProblemLanguageResultExecution timeMemory
1016142socpiteGarage (IOI09_garage)C++14
100 / 100
1 ms760 KiB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 2005;

int n, m;
int id[maxn], R[maxn], W[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> pq;
    for(int i = 1; i <= n; i++){
        cin >> R[i];
        pq.push(i);
    }
    queue<int> q;
    int ans = 0;
    for(int i = 1; i <= m; i++)cin >> W[i];
    for(int i = 1; i <= 2*m; i++){
        int x;
        cin >> x;
        if(x > 0)q.push(x);
        else pq.push(id[-x]);
        while(!q.empty() && !pq.empty()){
            id[q.front()] = pq.top();
            ans += W[q.front()]*R[pq.top()];
            pq.pop();
            q.pop();
        }
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...