제출 #858692

#제출 시각아이디문제언어결과실행 시간메모리
858692aykhnGarage (IOI09_garage)C++14
100 / 100
1 ms456 KiB
#include <bits/stdc++.h> // author : aykhn using namespace std; typedef long long ll; #define pb push_back #define ins insert #define mpr make_pair #define all(v) v.begin(), v.end() #define bpc __builtin_popcount #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define int ll #define infll 0x3F3F3F3F3F3F3F3F #define inf 0x3F3F3F3F const int MXN = 1e4 + 5; int n, m; int r[MXN], w[MXN], id[MXN]; queue<int> q; set<int> s; int res; void _() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> r[i]; for (int i = 1; i <= m; i++) cin >> w[i]; for (int i = 1; i <= n; i++) s.ins(i); for (int i = 1; i <= 2*m; i++) { int x; cin >> x; if (x < 0) { if (q.empty()) { s.ins(id[-x]); continue; } int y = q.front(); q.pop(); id[y] = id[-x]; id[-x] = 0; res += r[id[y]] * w[y]; continue; } if (s.empty()) { q.push(x); continue; } id[x] = *s.begin(); s.erase(s.begin()); res += r[id[x]] * w[x]; } cout << res << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; for (int i = 1; i <= t; i++) { _(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...