#include <bits/stdc++.h>
typedef long long ll;
const ll inf=1000000000000000000;
#define fr(i,c,d) for(ll i=c;i<=d;i++)
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pp push
using namespace std;
const int sz=173;
string str(string x,int l,int r){
string h;
for(int i=l;i<=r;i++){
h+=x[i];
}
return h;
}
int main(){
//int color[200001];
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n,m;
cin >> n >> m;
ll a[101]={0},b[101];
ll r[101];
ll w[2001];
for(int i=1;i<=n;i++){
cin >> r[i];
}
for(int i=1;i<=m;i++){
cin >> w[i];
}
ll ans=0;
queue<ll>q;
for(int i=1;i<=2*m;i++){
ll car,flag=0;
cin >> car;
if(car>0){
for(int j=1;j<=n;j++){
if(a[j]==0){
ans+=(w[car]*r[j]);
a[j]=1;
b[car]=j;
flag++;
break;
}
}
if(flag==0){
q.pp(car);
}
}
else{
car=-car;
a[b[car]]=0;
if(q.empty()) continue;
b[q.front()]=b[car];
a[b[q.front()]]=1;
ans+=(w[q.front()]*r[b[car]]);
q.pop();
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |