# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113097 | popovicirobert | Garage (IOI09_garage) | C++14 | 3 ms | 436 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 lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
vector <int> space(n + 1), car(m + 1);
for(i = 1; i <= n; i++) {
cin >> space[i];
}
for(i = 1; i <= m; i++) {
cin >> car[i];
}
queue < pair <int, int> > a, b;
for(i = 1; i <= 2 * m; i++) {
int id;
cin >> id;
if(id > 0) {
a.push({id, i});
}
else {
b.push({-id, i});
}
}
set <int> act;
for(i = 1; i <= n; i++) {
act.insert(i);
}
vector <int> where(m + 1);
ll ans = 0;
for(i = 1; i <= 2 * m && a.size(); i++) {
if(act.size() > 0) {
if(b.size() == 0 || (b.size() && a.front().second < b.front().second)) {
auto pos = *act.begin();
act.erase(act.begin());
ans += 1LL * car[a.front().first] * space[pos];
where[a.front().first] = pos;
a.pop();
}
else {
act.insert(where[b.front().first]);
b.pop();
}
}
else {
act.insert(where[b.front().first]);
b.pop();
}
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |