# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088669 | StefanSebez | Garage (IOI09_garage) | C++14 | 2 ms | 424 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;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
int main(){
int n,m;scanf("%i%i",&n,&m);
int a[n+10];for(int i=1;i<=n;i++) scanf("%i",&a[i]);
int b[m+10];for(int i=1;i<=m;i++) scanf("%i",&b[i]);
int q=2*m;
queue<int>kju;
int res=0;
int broj[n+10]={0};
while(q--){
//for(int i=1;i<=n;i++) printf("%i ",broj[i]);printf("\n");
int j;scanf("%i",&j);
if(j>0){
bool bul=false;
for(int i=1;i<=n;i++){
if(!broj[i]){
res+=a[i]*b[j];
broj[i]=j;
bul=true;
break;
}
}
if(!bul) kju.push(j);
}
else{
j=-j;
bool bul=false;
for(int i=1;i<=n;i++){
if(!broj[i]) bul=true;
if(broj[i]==j){
broj[i]=0;
}
}
if(!bul && kju.size()){
j=kju.front();kju.pop();
for(int i=1;i<=n;i++){
if(!broj[i]){
res+=a[i]*b[j];
broj[i]=j;
bul=true;
break;
}
}
}
}
}
printf("%i\n",res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |