# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
348796 | Mefarnis | Garage (IOI09_garage) | C++14 | 1 ms | 384 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 maxn 101
#define maxm 2001
using namespace std;
int n,m,ans;
int r[maxn];
int w[maxm];
int slot[maxm];
bool mark[maxn];
queue<int> Q;
int main() {
scanf("%d%d",&n,&m);
for( int i = 1 ; i <= n ; i++ )
scanf("%d",&r[i]);
for( int i = 1 ; i <= m ; i++ )
scanf("%d",&w[i]);
for( int q = 0 , id ; q < 2*m ; q++ ) {
scanf("%d",&id);
if(id > 0) {
int idx = -1;
for( int i = 1 ; i <= n ; i++ )
if(!mark[i]) {
idx = i;
slot[id] = i;
mark[i] = true;
ans += r[i] * w[id];
break;
}
if(idx == -1)
Q.push(id);
}
else {
id = -id;
if(Q.empty())
mark[slot[id]] = false;
else {
int car = Q.front();
Q.pop();
ans += r[slot[id]] * w[car];
slot[car] = slot[id];
}
}
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |