# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
650908 | rewer | Garage (IOI09_garage) | C++14 | 6 ms | 340 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 int long long
int n,m,cnt=0;
int r[60000];
int kg[60000];
int ar[60000];
bool b[60000];
deque<int> dq;
int x[60000];
map<int,int> mp;
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>r[i];
mp[r[i]]=0;
}
for(int i=1;i<=m;i++){
cin>>kg[i];
}
// sort(r+1,r+1+n);
for(int i=1;i<=2*m;i++){
cin>>x[i];
bool nospace=true;
if(x[i]>0){
for(int j=1;j<=n;j++){
if(!b[j]){
nospace=false;
mp[r[j]]=x[i];
b[j]=true;
cnt=cnt+kg[x[i]]*r[j];
break;
}
}
if(nospace)dq.push_back(x[i]);
}
else if(x[i]<0){
x[i]=-x[i];
for(int j=1;j<=n;j++){
if(mp[r[j]]==x[i]){
mp[r[j]]=0;
b[j]=false;
if(!dq.empty()){
mp[r[j]]=dq[0];
b[j]=true;
cnt=cnt+kg[dq[0]]*r[j];
dq.pop_front();
}
}
}
}
}
cout<<cnt<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |