# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
650748 | Spade1 | Garage (IOI09_garage) | C++14 | 2 ms | 344 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 pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;
const int N = 110, M = 2020;
int r[N], w[M];
int space[N];
queue<int> q;
void solve() {
int n, m; cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> r[i];
for (int i = 1; i <= m; ++i) cin >> w[i];
int ans = 0;
for (int i = 1; i <= 2*m; ++i) {
int j; cin >> j;
if (j > 0) {
q.push(j);
for (int i = 1; i <= n; ++i) {
if (space[i] == 0) {
space[i] = q.front();
ans += (r[i]*w[q.front()]);
q.pop();
break;
}
}
}
else {
for (int i = 1; i <= n; ++i) {
if (space[i] == -j) {
space[i] = 0;
if (!q.empty()) {
space[i] = q.front();
ans += (r[i]*w[q.front()]);
q.pop();
}
}
}
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |