#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
int rate[200];
int filled[200];
int weight[3000];
int loc[3000];
int main() {
int N, M;
cin >> N >> M;
for (int i = 0; i < N; i++) {
cin >> rate[i];
}
for (int i = 0; i < M; i++) {
cin >> weight[i];
}
memset(filled, 0, sizeof(filled));
queue<int> q;
ll tCost = 0;
for (int i = 0; i < 2 * M; i++) {
int x;
cin >> x;
if (x > 0) {
x--;
bool fSpace = false;
for (int j = 0; j < N; j++) {
if (!filled[j]) {
filled[j] = true;
loc[x] = j;
fSpace = true;
break;
}
}
if (!fSpace) {
q.push(x);
}
} else {
x = -x;
x--;
int cLoc = loc[x];
filled[cLoc] = false;
tCost += (ll) rate[cLoc] * weight[x];
if (q.size()) {
int nxt = q.front();
q.pop();
filled[cLoc] = true;
loc[nxt] = cLoc;
}
}
}
cout << tCost << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
340 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 |
376 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 |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
504 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |