Submission #853945

#TimeUsernameProblemLanguageResultExecution timeMemory
853945tue147Garage (IOI09_garage)C++14
100 / 100
2 ms476 KiB
# include <bits/stdc++.h>
using namespace std;

int n,m;
unsigned long long sum = 0;

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

    cin >> n >> m;
    int r[n];
    int w[m];
    set<int> s;
    unordered_map<int, int> store;
    queue<int> q;
    int temp;
    for (int i=0; i< n; i++){
        cin >> r[i];
        s.insert(i);
    }
    for (int i=0; i< m; i++){
        cin >> w[i];
    }
    for (int i=0; i< 2*m; i++){
        cin >> temp;
        if (temp > 0){
            if (!s.empty()){
                set<int>::iterator ptr = s.begin();
                sum += r[*ptr] * w[temp-1];
                store[temp] = *ptr;
                s.erase(ptr);
            }
            else{
                q.push(temp);
            }
        }
        else{
            temp = -temp;
            int place = store[temp];
            s.insert(place);
            store.erase(temp);
        }
        while (!q.empty() && !s.empty()){
            temp = q.front();
            q.pop();
            set<int>::iterator ptr = s.begin();
            sum += r[*ptr] * w[temp-1];
            store[temp] = *ptr;
            s.erase(ptr);
        }
    }
    cout << sum;
    return 0;
}

Compilation message (stderr)

garage.cpp: In function 'int main()':
garage.cpp:8:15: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
    8 |     ios_base::sync_with_stdio;
      |     ~~~~~~~~~~^~~~~~~~~~~~~~~
garage.cpp:8:15: warning: statement has no effect [-Wunused-value]
#Verdict Execution timeMemoryGrader output
Fetching results...