# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1094829 | salmon | Garage (IOI09_garage) | C++14 | 1 ms | 348 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>
using namespace std;
int N;
int M;
int R[110];
set<int> sat;
int inv[2110];
int tim[110];
int W[2100];
int x;
queue<int> q;
int main(){
scanf(" %d",&N);
scanf(" %d",&M);
for(int i = 0; i < N; i++){
scanf(" %d",&R[i]);
sat.insert(i);
}
for(int i = 1; i <= M; i++){
inv[i] = -1;
scanf(" %d",&W[i]);
}
long long int ans = 0;
for(int i = 0; i < M * 2; i ++){
scanf(" %d",&x);
if(x < 0){
x = -x;
sat.insert(inv[x]);
ans += R[inv[x]] * W[x];
if(!q.empty()){
x = q.front();
q.pop();
}
else x = -1;
}
if(x > 0){
if(sat.empty()){
q.push(x);
continue;
}
int l = *sat.begin();
sat.erase(sat.begin());
tim[l] = i;
inv[x] = l;
}
}
printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |