Submission #675891

#TimeUsernameProblemLanguageResultExecution timeMemory
675891CookieGarage (IOI09_garage)C++14
100 / 100
2 ms340 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; //ifstream fin("INTERNET.INP"); //ofstream fout("INTERNET.OUT"); #define ll long long #define vt vector #define pb push_back #define fi first #define se second #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define pii pair<int, int> #define pll pair<ll, ll> //#define int long long typedef unsigned long long ull; const int mxn = 2e3, sq = 317, mxv = 1e4; const ll mx = 1e9; const ll p[4] = {2, 3, 5, 7}; int n, m; int r[mxn + 1], w[mxn + 1], pos[mxn + 1]; set<int>s; queue<int>q; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> r[i]; s.insert(i); } int ans = 0; for(int i = 1; i <= m; i++)cin >> w[i]; for(int i = 0; i < 2 * m; i++){ int x; cin >> x; if(x > 0){ if(s.size()){ int p = *s.begin(); s.erase(p); pos[x] = p; ans += w[x] * r[p]; }else{ q.push(x); } }else{ x = -x; int nw = pos[x]; if(q.size()){ int cr = q.front(); q.pop(); pos[cr] = nw; ans += w[cr] * r[nw]; }else{ s.insert(nw); } } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...