#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N, M;
int rate[100];
int A[2000];
int pos[2000];
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M;
rep(i, N) cin >> rate[i];
rep(i, M) cin >> A[i];
set<int> empty;
rep(i, N) empty.insert(i);
queue<int> q;
long long cost = 0;
rep(_, 2*M) {
int x; cin >> x;
if (x>0) {
x--;
pos[x] = -1;
q.push(x);
}
else {
x=-x-1;
assert(pos[x] != -1);
empty.insert(pos[x]);
pos[x] = -1;
}
while (!empty.empty() && !q.empty()) {
int x = q.front(); q.pop();
int place = *empty.begin(); empty.erase(empty.begin());
pos[x] = place;
cost += 1LL*A[x]*rate[pos[x]];
}
}
cout << cost << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
612 KB |
Output is correct |
4 |
Correct |
2 ms |
688 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
2 ms |
688 KB |
Output is correct |
7 |
Correct |
2 ms |
688 KB |
Output is correct |
8 |
Correct |
2 ms |
688 KB |
Output is correct |
9 |
Correct |
2 ms |
708 KB |
Output is correct |
10 |
Correct |
2 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
884 KB |
Output is correct |
12 |
Correct |
2 ms |
884 KB |
Output is correct |
13 |
Correct |
2 ms |
884 KB |
Output is correct |
14 |
Correct |
2 ms |
884 KB |
Output is correct |
15 |
Correct |
2 ms |
884 KB |
Output is correct |
16 |
Correct |
3 ms |
884 KB |
Output is correct |
17 |
Correct |
3 ms |
884 KB |
Output is correct |
18 |
Correct |
3 ms |
900 KB |
Output is correct |
19 |
Correct |
3 ms |
928 KB |
Output is correct |
20 |
Correct |
3 ms |
972 KB |
Output is correct |