# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1096953 | vjudge1 | Garage (IOI09_garage) | C++17 | 1 ms | 452 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"
using namespace std;
#ifndef LOCAL
#define debug(...)
#endif
#define SZ(x) ((int) x.size())
#define int long long
#define vvi vector<vector<int>>
#define endl '\n'
#define pii pair<int, int>
#define all(v) (v).begin(), (v).end()
template <typename T>
istream &operator>>(istream& is, vector<T> &v) {
for (auto &x: v) is >> x;
return is;
}
void run_test() {
int n, m;
cin >> n >> m;
vector<int> rate(n+1), wt(m+1);
for (int i = 1; i <= n; i++) cin >> rate[i];
for (int i = 1; i <= m; i++) cin >> wt[i];
vector<int> ad(2*m);
cin >> ad;
vector<int> garage(n+1, -1);
queue<int> q;
int ans = 0;
for (int i = 0; i < 2*m; i++) {
int car = ad[i];
if (car < 0) {
for (int j = 1; j <= n; j++) {
if (garage[j] == -car) {
garage[j] = -1;
break;
}
}
}
if (car > 0) q.push(car);
if (q.empty()) continue;
int top = q.front();
bool parked = false;
for (int j = 1; j <= n; j++) {
if (garage[j] == -1) {
parked = true;
garage[j] = top;
ans += wt[top] * rate[j];
break;
}
}
if (parked) q.pop();
}
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--) {
run_test();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |