# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
539462 | MurotY | Garage (IOI09_garage) | C++14 | 3 ms | 472 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>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define ll long long
using namespace std;
const int N=1e6+7, M=1e9+7;
ll a[N], b[N];
void solve()
{
ll n, m;
cin >> n >> m;
for (int i=1;i<=n;i++) cin >> a[i];
for (int i=1;i<=m;i++) cin >> b[i];
map <ll,ll> mp, mp1;
deque <ll> v;
ll ans=0;
for (int i=1;i<=2*m;i++){
ll x;
cin >> x;
if (x > 0){
bool ok=0;
for (int i=1;i<=n;i++){
if (mp[i] == 0) {
mp[i]=1;
ans+=a[i]*b[x];
mp1[x]=i;
ok=1;
break;
}
}
if (ok == 0) v.push_back(x);
}
else {
if (v.size() == 0) mp[mp1[-x]]=0;
else {
ans+=a[mp1[-x]]*b[v[0]];
v.pop_front();
}
}
}
cout << ans;
}
int main()
{
ios;
int t=1;
// cin >> t;
while (t--){
solve();
cout << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |