Submission #1196026

#TimeUsernameProblemLanguageResultExecution timeMemory
1196026edga1Garage (IOI09_garage)C++20
30 / 100
1 ms332 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define pb push_back
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MOD 1000000007


int main()
{
    fastIO;
    int n,m;
    cin>>n>>m;
    vector<int> r(n),w(m+1);
    for(int i=0; i<n; i++) cin>>r[i];
    for(int i=1; i<=m; i++) cin>>w[i];
    queue<int> ie;
    stack<int> b;
    vector<int> g(m+1);
    int rez=0;
    for(int i=n-1; i>=0; i--) b.push(i);
    for(int i=0; i<m*2; i++){
        int c; cin>>c;
        if(c>0){
            ie.push(c);
        }else{
            b.push(g[abs(c)]);
        }
        while(ie.size()>0 && b.size()>0){
            rez+=r[b.top()]*w[ie.front()];
            g[ie.front()]=b.top();
            b.pop();
            ie.pop();
        }
    }
    cout<<rez;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...