# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134418 | sheismad | Garage (IOI09_garage) | C++14 | 3 ms | 380 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 <cstdio>
#include <iostream>
#include <queue>
using namespace std;
int const MAXN = 101,MAXM = 2001;
int park[MAXN];
int main() {
//freopen("input.txt","r",stdin);
int n,m,weight[MAXM],price[MAXN],car;
long long ans = 0;
queue<int> q;
scanf("%d %d\n",&n,&m);
for (int i=0;i<n;i++) scanf("%d",&price[i]);
for (int i=0;i<m;i++) scanf("%d",&weight[i]);
int j,mini = 0;
for (int i=0;i<m*2;i++) {
scanf("%d",&car);
j = 0;
//arrive
if (car>0) {
while (park[j] && j<n) j++;
//there is an empty space
if (j<n) {
if (q.empty()) {
park[j] = car; ans += price[j]*weight[car-1];
}
else {
q.push(car); park[j] = q.front(); ans += price[j]*weight[q.front()-1]; q.pop();
}
} // there is not
else q.push(car);
} //departure
else {
car *= -1;
while (park[j]!=car) j++;
park[j] = 0;
if (!q.empty()) {
park[j] = q.front();
ans += price[j]*weight[q.front()-1];
q.pop();
}
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |