# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445042 | cpp219 | Garage (IOI09_garage) | C++14 | 2 ms | 332 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.
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 2000 + 9;
const ll Log2 = 30;
const ll mod = 1e9 + 7;
priority_queue<ll,vector<ll>,greater<ll>> spare;
queue<ll> wait;
ll n,m,R[N],a[N],x,take[N];
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
ll ans = 0;
cin>>n>>m;
for (ll i = 1;i <= n;i++) cin>>R[i],spare.push(i);
for (ll i = 1;i <= m;i++) cin>>a[i];
for (ll i = 1;i <= 2*m;i++){
cin>>x;
if (x > 0){
if (!spare.empty()){
ll now = spare.top(); spare.pop();
take[x] = now; ans += R[now] * a[x];
}
else wait.push(x);
}
else{
x = -x; ll now = take[x]; spare.push(now);
while (!wait.empty() && !spare.empty()){
ll place = spare.top(); spare.pop();
ll car = wait.front(); wait.pop();
ans += R[place] * a[car]; take[car] = place;
}
}
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |