# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697750 | hiikunZ | Garage (IOI09_garage) | C++17 | 2 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;
using ll = long long int;
int main(){
ll N,M;
cin >> N >> M;
vector<ll> R(N),W(M),U(N,0),P(M,-1);
ll ans = 0;
for(ll i = 0;i < N;i++) cin >> R[i];
for(ll i = 0;i < M;i++) cin >> W[i];
queue<ll> que;
for(ll q = 0;q < M * 2;q++){
ll s;
cin >> s;
if(s > 0){
s--;
que.emplace(s);
}
else{
s *= -1;
s--;
U[P[s]] = 0;
}
while(!que.empty()){
ll ok = 0;
for(ll i = 0;i < N;i++){
if(U[i] == 0){
U[i] = 1;
P[que.front()] = i;
ans += R[i] * W[que.front()];
que.pop();
ok = 1;
break;
}
}
if(!ok) break;
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |