Submission #717654

#TimeUsernameProblemLanguageResultExecution timeMemory
717654ZeroCoolGarage (IOI09_garage)C++14
100 / 100
2 ms340 KiB
#include <bits/stdc++.h> #define ll long long #define inf INT_MAX #define endl '\n' using namespace std; const int mxn = 20; void solve(){ int n, m; long long result = 0; cin>>n>>m; vector<int>r(n + 1), w(m + 1); for(int i = 1;i <= n;++i)cin>>r[i]; for(int i = 1;i <= m;++i)cin>>w[i]; vector<int>p(n + 1); queue<int>q; for(int i = 0;i < 2 * m;++i){ int c; cin>>c; bool park = false; if(c > 0){ for(int j = 1;j <= n;++j){ if(!p[j]){ p[j] = c; result += w[c] * r[j]; park = true; break; } } if(!park){ q.push(c); } } else{ for(int j = 1;j <= n;++j){ if(-c == p[j]){ p[j] = 0; break; } } if(!q.empty()){ int cur = q.front(); q.pop(); for(int j = 1;j <= n;++j){ if(!p[j]){ p[j] = cur; result += w[cur] * r[j]; break; } } } } } cout<<result<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin>>t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...