Submission #481576

# Submission time Handle Problem Language Result Execution time Memory
481576 2021-10-21T08:10:22 Z SlavicG Garage (IOI09_garage) C++17
100 / 100
2 ms 460 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()
 
void solve()
{  
    int n, m;
    cin >> n >> m;
    vector<int> a(n), w(m + 1);
    forn(i, n) cin >> a[i];
    forn(i, m) cin >> w[i + 1];

    set<int> free;

    for(int i = 0;i < n;++i)free.insert(i);

    ll ans = 0;

    int q = 2 * m;

    map<int,int> spot;

    queue<int> v;
    while(q--)
    {
        int x;
        cin >> x;
        bool depart = false;
        if(x < 0){
            depart = true;
            x = -x;
        }

        if(depart){
            ans += w[x] * a[spot[x]];
            free.insert(spot[x]);
        }else v.push(x);

        while(sz(v) && sz(free)){
            int c = v.front();
            spot[c] = *free.begin();
            free.erase(free.begin());
            v.pop();
        }
    }

    cout << ans << '\n';
}   
 
int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct