#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N=104;
const int M=2004;
long long n,m,Cars;
long long R[N],W[M],Id[M];
long long ANS;
bool F[N];
queue < int > q;
main () {
cin>>n>>m;
for (int i=1; i<=n; i++)
cin>>R[i];
for (int i=1; i<=m; i++)
cin>>W[i];
for (int i=1; i<=2*m; i++) {
int idx=0;
cin>>idx;
if (idx<0) idx=-idx,Cars--,F[Id[idx]]=0;
else q.push(idx);
while (q.size() && n>Cars) {
int ID=q.front();
q.pop();
for (int j=1; j<=n; j++)
if (!F[j]) {
Cars++,F[j]=1,Id[ID]=j;
ANS+=R[j]*W[ID];
break;
}
}
}
cout<<ANS<<endl;
}
Compilation message
garage.cpp:18:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
404 KB |
Output is correct |
18 |
Correct |
5 ms |
416 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |