Submission #275025

#TimeUsernameProblemLanguageResultExecution timeMemory
275025Bill_00Garage (IOI09_garage)C++14
45 / 100
2 ms384 KiB
#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); int n,m; cin >> n >> m; int a[101]={0},b[101]; int r[101]; int w[2001]; for(int i=1;i<=n;i++){ cin >> r[i]; } for(int i=1;i<=m;i++){ cin >> w[i]; } int 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 timeMemoryGrader output
Fetching results...