# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211930 | aloo123 | Garage (IOI09_garage) | C++14 | 5 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.
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define in insert
#define int ll
using namespace std;
using namespace __gnu_pbds;
const ll N =(2e5);
const ll MOD = 998244353;
const ll INF = 1e16;
const ll LOG = 25;
long long binpow(long long a, long long b) {
// a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a ;
a = a * a ;
b >>= 1;
}
return res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll n,m;
cin >>n >> m;
ll r[n+1];
for(int i =1;i<=n;i++)
cin >> r[i];
ll w[m+1];
for(int i =1;i<=m;i++){
cin >> w[i];
}
vector<bool> empty(n+1,true);
vll pos(m+1);
ll ans =0;
queue<ll> q;
for(int i = 1;i<=2*m;i++){
ll x;
cin >>x;
if(x > 0){
ll id=-1;
for(int j = 1;j<=n;j++){
if(empty[j]){
id=j;break;
}
}
if(id != -1){
empty[id]=false;
pos[x] = id;
ans+=(w[x]*r[id]);
}
else{
q.push(x);
}
}
else{
ll p = pos[-x];
empty[p] = true;
while(!q.empty()){
ll gg=q.front();
ll id=-1;
for(int j = 1;j<=n;j++){
if(empty[j]){
id=j;break;
}
}
if(id != -1){
empty[id]=false;
pos[gg] = id;
ans+=(w[gg]*r[id]);
q.pop();
}
else{
break;
}
}
}
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |