Submission #539462

#TimeUsernameProblemLanguageResultExecution timeMemory
539462MurotYGarage (IOI09_garage)C++14
40 / 100
3 ms472 KiB
#include <bits/stdc++.h> #define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ff first #define ss second #define ll long long using namespace std; const int N=1e6+7, M=1e9+7; ll a[N], b[N]; void solve() { ll n, m; cin >> n >> m; for (int i=1;i<=n;i++) cin >> a[i]; for (int i=1;i<=m;i++) cin >> b[i]; map <ll,ll> mp, mp1; deque <ll> v; ll ans=0; for (int i=1;i<=2*m;i++){ ll x; cin >> x; if (x > 0){ bool ok=0; for (int i=1;i<=n;i++){ if (mp[i] == 0) { mp[i]=1; ans+=a[i]*b[x]; mp1[x]=i; ok=1; break; } } if (ok == 0) v.push_back(x); } else { if (v.size() == 0) mp[mp1[-x]]=0; else { ans+=a[mp1[-x]]*b[v[0]]; v.pop_front(); } } } cout << ans; } int main() { ios; int t=1; // cin >> t; while (t--){ solve(); cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...