제출 #601053

#제출 시각아이디문제언어결과실행 시간메모리
601053SlyGaleebGarage (IOI09_garage)C++17
100 / 100
2 ms360 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ld long double
#define F first
#define S second
const ll N = 2e5 + 5;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m,ans=0;
    cin >> n >> m;
    vector<int>v(n+1),w(m+1);
    priority_queue<int,vector<int>,greater<int>>pq;
    queue<int>q;
    map<int,int>mp;
    for (int i = 1; i <= n; ++i) {
        cin >> v[i];
        pq.push(i);
    }
    for (int i = 1; i <= m; ++i)
        cin >> w[i];
    for (int i = 0; i < 2*m; ++i) {
        while (!q.empty() && !pq.empty()) {
            ans += w[q.front()]*v[pq.top()];
            mp[q.front()] = pq.top();
            q.pop();
            pq.pop();
        }
        int a;
        cin >> a; 
        if (a>0) {
            if (pq.empty())
                q.push(a);
            else {
                ans += w[a]*v[pq.top()];
                mp[a] = pq.top();
                pq.pop();
            }
        }
        else {
            pq.push(mp[-a]);
            mp.erase(-a);
        }
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...