Submission #866255

# Submission time Handle Problem Language Result Execution time Memory
866255 2023-10-25T16:13:42 Z Bula Garage (IOI09_garage) C++14
100 / 100
2 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1), b(m + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= m; i++) cin >> b[i];

    set<int> st;
    queue<int> q;
    map<int, int> mp;
    for(int i = 1; i <= n; i++) st.insert(i);

    int ans = 0;
    for(int i = 1; i <= 2 * m; i++){
        int x;
        cin >> x;
        if(x > 0){
            if(st.size() == 0){
                q.push(x);
            }else{
                if(q.size() == 0){
                    int k = *st.begin();
                    ans += a[k] * b[x];
                    mp[x] = k;
                    st.erase(st.begin());
                }else{
                    int k = *st.begin();
                    int p = q.front();
                    ans += a[k] * b[p];
                    mp[p] = k;
                    st.erase(st.begin());
                    q.pop();
                    q.push(x);
                }
            }
        }else{
            st.insert(mp[abs(x)]);
            if(q.size() > 0){
                int k = *st.begin();
                int p = q.front();
                ans += a[k] * b[p];
                mp[p] = k;
                st.erase(st.begin());
                q.pop();
            }
        }
    }
    cout << ans << endl;
}

Compilation message

garage.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct