# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
724991 | stevancv | Garage (IOI09_garage) | C++14 | 2 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e3 + 2;
const int inf = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
set<int> s;
for (int i = 0; i < n; i++) s.insert(i);
queue<int> q;
vector<int> in(m, -1);
for (int z = 0; z < 2 * m; z++) {
int j; cin >> j;
if (j < 0) j = -j;
j -= 1;
if (in[j] == -1) {
if (!s.empty()) {
int i = *s.begin();
s.erase(i);
in[j] = i;
}
else q.push(j);
}
else {
if (!q.empty()) {
int jj = q.front();
in[jj] = in[j];
q.pop();
}
else s.insert(in[j]);
}
}
int ans = 0;
for (int i = 0; i < m; i++) ans += a[in[i]] * b[i];
cout << ans << en;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |