# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
152323 | miello | Garage (IOI09_garage) | C++11 | 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 <bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define emb emplace_back
#define em emplace
#define ii pair<int,int>
#define iii pair<int ,ii>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define allc(x) x.begin(),x.end(),cmp
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int INF = 0x3f3f3f3f;
const int MXN = 2005;
int cost[MXN] , w[MXN] , l[MXN];
bool chk[MXN];
queue<int> q;
int main(){
int n , m;
scanf("%d %d",&n,&m);
for(int i = 1 ; i <= n ; i++){
scanf("%d",&cost[i]);
}
for(int i = 1 ; i <= m ; i++){
scanf("%d",&w[i]);
}
int ans = 0;
for(int i = 0 ; i < 2 * m ; i++){
int x;
scanf("%d",&x);
if(x < 0){
x = abs(x);
// printf("%d %d %d\n",x,cost[l[x]] , l[x]);
ans += cost[l[x]] * w[x];
chk[l[x]] = 0;
if(q.size()){
int u = q.front();
chk[l[x]] = 1;
l[u] = l[x];
q.pop();
}
}else{
bool non = 0;
for(int j = 1 ; j <= n ; j++){
if(!chk[j]){
non = 1;
chk[j] = 1;
l[x] = j;
break;
}
}
if(!non){
q.push(x);
}
}
}
printf("%d",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |