# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52902 | 2018-06-27T06:57:56 Z | szawinis | Garage (IOI09_garage) | C++17 | 4 ms | 868 KB |
#include <bits/stdc++.h> using namespace std; int n, m, nxt = 1, r[101], slot[2001], w[2001]; long long ans; queue<int> wait; priority_queue<int, vector<int>, greater<int> > avail; int main() { scanf("%d%d",&n,&m); for(int i = 1; i <= n; i++) scanf("%d", &r[i]), avail.push(i); for(int i = 1; i <= m; i++) scanf("%d", &w[i]); for(int i = 1; i <= 2*m; i++) { int x; scanf("%d", &x); if(x > 0) { if(wait.empty() && !avail.empty()) slot[x] = avail.top(), avail.pop(); else wait.push(x); } else { x *= -1; ans += r[slot[x]]*w[x]; avail.push(slot[x]); slot[x] = 0; if(!wait.empty()) { slot[wait.front()] = avail.top(); avail.pop(); wait.pop(); } } } printf("%lld", ans); }
Compilation message
# | Verdict | Execution time | Memory | 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 | 3 ms | 440 KB | Output is correct |
5 | Correct | 2 ms | 496 KB | Output is correct |
6 | Correct | 2 ms | 656 KB | Output is correct |
7 | Correct | 2 ms | 656 KB | Output is correct |
8 | Correct | 2 ms | 656 KB | Output is correct |
9 | Correct | 2 ms | 656 KB | Output is correct |
10 | Correct | 2 ms | 656 KB | Output is correct |
11 | Correct | 3 ms | 764 KB | Output is correct |
12 | Correct | 2 ms | 764 KB | Output is correct |
13 | Correct | 2 ms | 764 KB | Output is correct |
14 | Correct | 3 ms | 816 KB | Output is correct |
15 | Correct | 3 ms | 816 KB | Output is correct |
16 | Correct | 3 ms | 816 KB | Output is correct |
17 | Correct | 3 ms | 816 KB | Output is correct |
18 | Correct | 4 ms | 816 KB | Output is correct |
19 | Correct | 3 ms | 816 KB | Output is correct |
20 | Correct | 4 ms | 868 KB | Output is correct |