#include <bits/stdc++.h>
using namespace std;
int a[105], c[105], b[2005];
queue<int> q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, ans=0;
cin >> n >> m;
for (int i=1; i<=n; i++)
cin >> a[i];
for (int i=1; i<=m; i++)
cin >> b[i];
for (int i=0; i<m*2; i++)
{
int x;
cin >> x;
if (x>0)
{
for (int j=1; j<=n; j++)
{
if (!c[j])
{
ans+=a[j]*b[x];
c[j]=x;
break;
}
if (j==n)
q.push(x);
}
}
else
{
for (int j=1; j<=n; j++)
{
if (c[j]==-x)
{
c[j]=0;
break;
}
}
if (!q.empty())
{
int u=q.front();
q.pop();
for (int j=1; j<=n; j++)
{
if (!c[j])
{
ans+=a[j]*b[u];
c[j]=u;
break;
}
}
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 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 |
0 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 |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
356 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |