제출 #228795

#제출 시각아이디문제언어결과실행 시간메모리
228795osaaateiasavtnlGarage (IOI09_garage)C++14
100 / 100
6 ms384 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcount #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC const int N = 2007; int c[N], w[N]; bool used[N]; int pos[N]; int n, m, ans = 0; queue <int> q; void add(int i) { //cout << "add " << i << endl; pos[i] = -1; for (int j = 1; j <= n; ++j) { if (!used[j]) { pos[i] = j; break; } } if (pos[i] != -1) { //cout << "place " << i << "->" << pos[i] << ' ' << w[i] * c[pos[i]] << endl; used[pos[i]] = 1; ans += w[i] * c[pos[i]]; } else { q.push(i); } //cout << "exit" << endl; } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> c[i]; for (int i = 1; i <= m; ++i) cin >> w[i]; for (int t = 0; t < 2 * m; ++t) { int i; cin >> i; if (i > 0) { add(i); } else { i = -i; used[pos[i]] = 0; if (q.size()) { i = q.front(); q.pop(); add(i); } } //cout << "end " << t << endl; } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...