# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
567634 | losmi247 | Garage (IOI09_garage) | C++14 | 2 ms | 356 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>
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int n, m;
bool P[102];
int pos[2002], cont;
int R[102], W[2002];
int car;
queue<int> Q;
int firstP(){
for( int i = 1; i <= n; i++ )
if( !P[i] )
return i;
}
int main(){
optimizar_io
cin >> n >> m;
for( int i = 1; i <= n; i++ )
cin >> R[i];
for( int i = 1; i <= m; i++ )
cin >> W[i];
cont = n;
int ans = 0;
for( int i = 1; i <= 2 * m; i++ ){
cin >> car;
if( car > 0 ){
if( cont ){
int f = firstP();
cont--; P[f] = true;
ans += R[f] * W[car];
pos[car] = f;
} else {
Q.push( car );
}
} else {
car *= -1;
int f = pos[car];
P[f] = false; cont++;
if( !Q.empty() ){
car = Q.front();
Q.pop();
P[f] = true; cont--;
pos[car] = f;
ans += R[f] * W[car];
}
}
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |