# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
866255 | Bula | Garage (IOI09_garage) | C++14 | 2 ms | 604 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |