# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
999285 | SonicML | Garage (IOI09_garage) | C++14 | 1 ms | 604 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 <iostream>
#include <queue>
using namespace std;
int n, m;
int const NMAX = 100;
int arr[1 + NMAX];
int taken[1 + NMAX];
int const MMAX = 2000;
int weight[1 + MMAX];
int pos[1 + MMAX];
queue <int> q;
int main() {
cin >> n >> m;
for(int i = 1;i <= n;i++) {
cin >> arr[i];
}
for(int i = 1;i <= m;i++) {
cin >> weight[i];
}
int canPark = n, ans = 0;
for(int t = 1;t <= 2 * m;t++) {
int c;
cin >> c;
if(c > 0) {
if(canPark == 0) {
q.push(c);
}else {
bool foundSpot = false;
for(int i = 1;i <= n && !foundSpot;i++) {
if(taken[i] == false) {
ans += arr[i] * weight[c];
taken[i] = true;
foundSpot = true;
canPark--;
pos[c] = i;
}
}
}
} else {
c = -c;
if(canPark == 0) {
if(!q.empty()) {
ans += arr[pos[c]] * weight[q.front()];
q.pop();
}else{
taken[pos[c]] = false;
canPark++;
}
} else {
taken[pos[c]] = false;
canPark++;
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |