# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
275027 | Bill_00 | Garage (IOI09_garage) | C++14 | 1 ms | 384 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>
typedef long long ll;
const ll inf=1000000000000000000;
#define fr(i,c,d) for(ll i=c;i<=d;i++)
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pp push
using namespace std;
const int sz=173;
string str(string x,int l,int r){
string h;
for(int i=l;i<=r;i++){
h+=x[i];
}
return h;
}
int main(){
//int color[200001];
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n,m;
cin >> n >> m;
ll a[101]={0},b[101];
ll r[101];
ll w[2001];
for(int i=1;i<=n;i++){
cin >> r[i];
}
for(int i=1;i<=m;i++){
cin >> w[i];
}
ll ans=0;
queue<int>q;
for(int i=1;i<=2*m;i++){
int car,flag=0;
cin >> car;
if(car>0){
for(int j=1;j<=n;j++){
if(a[j]==0){
ans+=(w[car]*r[j]);
a[j]=1;
b[car]=j;
flag++;
break;
}
}
if(flag==0){
q.pp(car);
}
}
else{
car=-car;
a[b[car]]=0;
if(q.empty()) continue;
b[q.front()]=b[car];
a[b[q.front()]]=1;
ans+=(w[q.front()]*r[b[car]]);
q.pop();
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |