Submission #1203601

#TimeUsernameProblemLanguageResultExecution timeMemory
1203601Hamed_GhaffariGarage (IOI09_garage)C++20
100 / 100
1 ms328 KiB
#include<bits/stdc++.h> using namespace std; const int MXN = 2008; int n, m, r[MXN], w[MXN], wh[MXN]; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> m; for(int i=1; i<=n; i++) cin >> r[i]; for(int i=1; i<=m; i++) cin >> w[i]; set<int> st; for(int i=1; i<=n; i++) st.insert(i); m *= 2; queue<int> q; int ans = 0; while(m--) { int i; cin >> i; if(i>0) { if(st.empty()) q.push(i); else { ans += r[*st.begin()]*w[i]; wh[i] = *st.begin(); st.erase(st.begin()); } } else { if(wh[-i]) st.insert(wh[-i]); if(!q.empty()) { ans += r[*st.begin()]*w[q.front()]; wh[q.front()] = *st.begin(); q.pop(); st.erase(st.begin()); } } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...