#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, M)
#define ffa ffi ffj
#define s <<" "<<
#define w cout
#define e "\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define int ll
const int MAXN=100, MAXM=2000, INF=1000000000000000000;
///500,000,000
int N, M, R[MAXN], W[MAXM], spot[MAXM], out;
priority_queue<int> open;
queue<int> next1;
main() {
//ifstream cin("test.in");
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> M;
ffi cin >> R[i];
ffj cin >> W[j];
ffi open.push(-i);
For (j, 0, 2*M) {
int act; cin >> act;
if (act < 0) {
act *= -1;
act--;
open.push(-spot[act]);
if (!next1.empty()) {
int act = next1.front();
next1.pop();
int take = -open.top();
open.pop();
out += W[act]*R[take];
spot[act] = take;
}
}
else {
act--;
if (!open.empty()) {
int take = -open.top();
open.pop();
out += W[act]*R[take];
spot[act] = take;
}
else next1.push(act);
}
}
w<< out<<e;
}
Compilation message
garage.cpp:22:6: 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 |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
444 KB |
Output is correct |
5 |
Correct |
2 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
732 KB |
Output is correct |
12 |
Correct |
2 ms |
732 KB |
Output is correct |
13 |
Correct |
2 ms |
732 KB |
Output is correct |
14 |
Correct |
2 ms |
744 KB |
Output is correct |
15 |
Correct |
2 ms |
744 KB |
Output is correct |
16 |
Correct |
2 ms |
744 KB |
Output is correct |
17 |
Correct |
3 ms |
744 KB |
Output is correct |
18 |
Correct |
3 ms |
748 KB |
Output is correct |
19 |
Correct |
3 ms |
832 KB |
Output is correct |
20 |
Correct |
3 ms |
832 KB |
Output is correct |