#pragma comment(linker, "/STACK:100000000")
#include <bits/stdc++.h>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
#define pb push_back
#define in insert
#define pll pair<ll,ll>
#define vpl vector<pll>
#define vll vector <ll>
#define vl vector<ll>
#define sl set<ll>
#define msl multiset<ll>
#define mll map<ll,ll>
#define mmll multimap<ll,ll>
#define mcl map<char,ll>
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define endl "\n"
#define speed ios_base::sync_with_stdio(false);cin.tie();cout.tie()
#define ll long long
#define ull unsigned long long
#define LMX LLONG_MAX
using namespace std;
#define REP(i, n) for (ll i=0;i<(n);i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define rep(a) F0R(_, a)
#define each(a, x) for (auto &a : x)
/*
#pragma omp parallel for
#pragma GCC optimize("0fast")
#pragma GCC target ("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
ll price[101],weight[2001];
ll park;
set <ll> s1;
map <ll,ll> m1;
deque <ll> d1;
void solve()
{
ll n,m,ans=0;
cin>>n>>m;
for(ll i=1;i<=n;i++)
{
s1.in(i);
}
for(ll i=0;i<n;i++)
{
cin>>price[i+1];
}
for(ll i=0;i<m;i++)
{
cin>>weight[i+1];
}
for(ll i=0;i<2*m;++i)
{
ll car;
cin>>car;
if(car>0)
{
if(!s1.empty())
{
park=*(s1.begin());
ans+=weight[car]*price[park];
s1.erase(s1.begin());
m1[car]=park;
}
else
{
d1.push_back(car);
}
}
else
{
park=m1[-car];
if(!d1.empty())
{
car=d1[0];
ans+=weight[car]*price[park];
m1[car]=park;
d1.pop_front();
}
else
{
s1.in(park);
}
}
}
cout<<ans;
}
int main ()
{
ll t=1;
//cin>>t;
while(t--)
{
solve();
}
}
/*
string
length
*/
/*
auto locate = [&](int x) -> int {
for (int i = 0; i < N; i++)
if (P[i] == x)
return i;
return -1;
};
function in funcition
*/
Compilation message
garage.cpp:1: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
1 | #pragma comment(linker, "/STACK:100000000")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
444 KB |
Output is correct |
20 |
Correct |
2 ms |
444 KB |
Output is correct |